Wednesday 16 January 2013

org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session

,

Exception: 

com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Access denied for user ''@'localhost' to database 'school' at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:885) at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3421) at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1247) at com.mysql.jdbc.Connection.createNewIO(Connection.java:2775) at com.mysql.jdbc.Connection.(Connection.java:1555) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285) at java.sql.DriverManager.getConnection(DriverManager.java:582) at java.sql.DriverManager.getConnection(DriverManager.java:154)...

Reason 

  1. you are passing transient object instead of persistent object for delete

Possible solution : 

  1. Pass persistent object instead of transient object.

For example :

you would be trying something like this.Here studentToDelete is transient.

    public void deleteStudent(Student studentToDelete)
    {
        Session session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();
        // Here studentToDelete is transient object
        session.delete(studentToDelete);
        session.getTransaction().commit();
        session.flush();
    }

We will remove persisted object and pass to delete function like below one.

    public void deleteStudentA(Student studentToDelete)
    {
        Session session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();
        // Getting persisted object of Student.
        Student persistentStudent = (Student) session.get(Student.class, studentToDelete.getId());
        session.delete(persistentStudent);
        session.getTransaction().commit();
        session.flush();
    }
Read more →

Tuesday 15 January 2013

javax.servlet.jsp.JspException: Cannot find message resources under key org.apache.struts.action.MESSAGE

,

Exception: 

javax.servlet.jsp.JspException: Cannot find message resources under key org.apache.struts.action.MESSAGE at org.apache.struts.taglib.TagUtils.retrieveMessageResources(TagUtils.java:1189) at org.apache.struts.taglib.TagUtils.message(TagUtils.java:1038) at org.apache.struts.taglib.TagUtils.message(TagUtils.java:1013) at org.apache.struts.taglib.bean.WriteTag.retrieveFormatString(WriteTag.java:254) at org.apache.struts.taglib.bean.WriteTag.formatValue(WriteTag.java:317) at org.apache.struts.taglib.bean.WriteTag.doStartTag(WriteTag.java:232)...

Reason 

  1. you have not included properties file in  resource stuts config file.

Possible solution : 

  1. Define a property file and add in resources of struts-config.xml.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC 
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" 
"http://jakarta.apache.org/struts/dtds/struts-config_1_3.dtd">
 
<struts-config>
 
    <message-resources
        parameter="com.test.common.properties.person" />
 
</struts-config>

Read more →

Monday 14 January 2013

com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Access denied for user ''@'localhost' to database 'school'

,

Exception: 

java.lang.ClassNotFoundException: javax.transaction.Synchronization at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233) at org.hibernate.impl.SessionImpl.(SessionImpl.java:248) at org.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:627) at org.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:651) at org.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:659)...

Reason 

you have not included jta.jar 

Possible solution : 

  1. Download jta.jar from http://mvnrepository.com/artifact/javax.transaction/jta
    and include it in library.
    2. For maven user, Include  jta in pom.xml
        
<dependency>
    <groupId>javax.transaction</groupId>
    <artifactId>jta</artifactId>
    <version>1.1</version>
</dependency>
Read more →

Sunday 13 January 2013

java.lang.ClassNotFoundException: javax.transaction.Synchronization

,

Exception: 

com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Access denied for user ''@'localhost' to database 'school' at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:885) at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3421) at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1247) at com.mysql.jdbc.Connection.createNewIO(Connection.java:2775) at com.mysql.jdbc.Connection.(Connection.java:1555) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285) at java.sql.DriverManager.getConnection(DriverManager.java:582) at java.sql.DriverManager.getConnection(DriverManager.java:154)...

Reason 

  1. your username and password are incorrect
  2. your username does not have enough privilege on database
  3. you might be trying to access wrong database.

Possible solution : 

  1. Check your username and password
  2. Check privilege assigned to your username or role from which you are trying to access database.you might not be granted permission to access the database
  3. Check the database you are trying to access.you might be trying to access wrong database.
Read more →

java.lang.ClassNotFoundException: javassist.util.proxy.MethodFilter

,

Exception: 

java.lang.ClassNotFoundException: javassist.util.proxy.MethodFilter at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233) at org.hibernate.bytecode.javassist.BytecodeProviderImpl.getProxyFactoryFactory(BytecodeProviderImpl.java:49) at org.hibernate.tuple.entity.PojoEntityTuplizer.buildProxyFactoryInternal(PojoEntityTuplizer.java:207) at org.hibernate.tuple.entity.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:185)...

Reason 

you have not included javassist.jar 

Possible solution : 

  1. Download javassist.jar from http://www.csg.is.titech.ac.jp/~chiba/javassist and include it in library.
    2 . For maven user, Include javassist in pom.xml
        
<dependency>
    <groupId>javassist</groupId>
    <artifactId>javassist</artifactId>
    <version>3.12.1.GA</version>
</dependency>
Read more →

Saturday 5 January 2013

org.hibernate.HibernateException: Unable to instantiate default tuplizer

,

Exception: 

Caused by: org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]
    at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:108)
    at org.hibernate.tuple.entity.EntityTuplizerFactory.constructDefaultTuplizer(EntityTuplizerFactory.java:133)
    at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.<init>(EntityEntityModeToTuplizerMapping.java:80)
    at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:322)
    at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:485)
    at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:133)
    at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:84)
    at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:286)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1872)...

Reason 

you have use mismatch field in hbm which is not present in entity or database table.

Possible solution : 

  1. Check your entity field spelling in entity and hbm.
  2. Check your name of table assign in hbm.
  3. Check the entity class name assign in hbm.


Read more →

Thursday 3 January 2013

Check element exists in javascript

,
Code to check if element exist of not.
 You can check element exist or not with javascript by it id or name.

Check Element exist in Javascript

With Id :

var check = document.getElementById("elementId");
if(check.length != 0)
{
      alert('I am present');
}

With Name:
 
var check = document.getElementsByName("elementName");
if(check.length != 0)
{
      alert('I am present');
}


Check Element exist in jQuery

With Id :

if ($('#elementId').length > 0) { 
    // it exists 
}
Read more →