Posts

Showing posts from November, 2010

Hibernate: a different object with the same identifier value was already associated with the session

People working with Hibernate might be familiar with the below error. org.springframework.orm.hibernate3.HibernateSystemException: a different object with the same identifier value was already associated with the session: nested exception is org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session This exception is generated when we try to load an instance object in session which has been already loaded by hibernate. Easier said than done. Hibernate considers two persistent entities identical if the two rows of the table can be said identical. Above error could be generated in many ways and there may be various solutions on net like using session merge etc to get away with the problem. I will discuss here the reason for me getting this problem and the way I resolved it. Below is the code which generated the exception for me. Following is the method which caused the exception @Transactional(propagation=Propagation.

Context initialization failed - java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder

I received the following error while running a Spring and Hibernate application Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/ applicationContext.xml ]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder Caused by: java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder at org.slf4j.LoggerFactory. (LoggerFact

org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]

This Exception during the maven build in an hibernate based project could come due to various reasons. Primarily one should look into the complete stack trace. The further exception usually do give clue of the actual problem. I my case, the stack trace revealed the below issue Exception in thread "main" org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer] at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:110) at org.hibernate.tuple.entity.EntityTuplizerFactory.constructDefaultTuplizer(EntityTuplizerFactory.java:135) at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping. (EntityEntityModeToTuplizerMapping.java:80) at org.hibernate.tuple.entity.EntityMetamodel. (EntityMetamodel.java:323) at org.hibernate.persister.entity.AbstractEntityPersister. (AbstractEntityPersister.java:456) at org.hibernate.persister.entity.SingleTableEntityPersister. (SingleT

java.lang.nosuchmethoderror org.objectweb.asm.classwriter

I was working on a RESTFul Service based project. Recently I migrated the plain JDBC DAO layer to the hibernate based orm layer. As a first step I migrated one of the DAO class. When I deployed the complete solution in Tomcat, I faced the following error java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter. (Z)V at net.sf.cglib.core.DebuggingClassWriter. (Debu ggingClassWriter.java:47) at net.sf.cglib.core.DefaultGeneratorStrategy.getClas sWriter(DefaultGeneratorStrategy.java:30) at net.sf.cglib.core.DefaultGeneratorStrategy.generat e(DefaultGeneratorStrategy.java:24) at net.sf.cglib.core.AbstractClassGenerator.create(Ab stractClassGenerator.java:216) at net.sf.cglib.core.KeyFactory$Generator.create(KeyF actory.java:145) at net.sf.cglib.core.KeyFactory.create(KeyFactory.jav a:117) at net.sf.cglib.core.KeyFactory.create(KeyFactory.jav a:108) at net.sf.cglib.core.KeyFactory.create(KeyFactory.jav a:104) at net.sf.cglib.proxy.Enhancer. (Enhancer.java :69) at java.lang.Class.forN