Showing posts with label Hibernate. Show all posts
Showing posts with label Hibernate. Show all posts

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 →

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 →