Mar 24

ids for this class must be manually assigned before calling save()

Exception in thread “main” org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save().

Exception in thread “main” org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): com.hr.hibernate.model.Employee
at org.hibernate.id.Assigned.generate(Assigned.java:33)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:98)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
at com.hibernate.util.HibernateConfig.main(HibernateConfig.java:30) Continue reading

Mar 24

Failed.org.hibernate.AnnotationException: No identifier specified for entity

Failed.org.hibernate.AnnotationException: No identifier specified for entity:

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Version).
log4j:WARN Please initialize the log4j system properly.
Initial SessionFactory creation failed.org.hibernate.AnnotationException: No identifier specified for entity: com.hr.hibernate.model.Employee
Exception in thread “main” java.lang.ExceptionInInitializerError
at com.hibernate.util.HibernateUtil.buildSessionFactory(HibernateUtil.java:19)
at com.hibernate.util.HibernateUtil.<clinit>(HibernateUtil.java:8)
at com.hibernate.util.HibernateConfig.main(HibernateConfig.java:25)
Caused by: org.hibernate.AnnotationException: No identifier specified for entity: com.hr.hibernate.model.Employee
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:626)
at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:452)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:268)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1283)
at com.hibernate.util.HibernateUtil.buildSessionFactory(HibernateUtil.java:13)
… 2 more Continue reading

Mar 22

org.hibernate.MappingException: Unknown entity

Exception in thread “main” org.hibernate.MappingException: Unknown entity: com.hr.hibernate.model.Employee

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Version).
log4j:WARN Please initialize the log4j system properly.
Exception in thread “main” org.hibernate.MappingException: Unknown entity: com.hr.hibernate.model.Employee
at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:548)
at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1338) Continue reading

Mar 22

org.hibernate.MappingExceptAn AnnotationConfiguration instance is required to use

Hibernate Exception : An AnnotationConfiguration instance is required to use

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Initial SessionFactory creation failed.org.hibernate.MappingException: An AnnotationConfiguration instance is required to use <mapping/>
Exception in thread “main” java.lang.ExceptionInInitializerError
at com.hibernate.util.HibernateUtil.buildSessionFactory(HibernateUtil.java:20)
at com.hibernate.util.HibernateUtil.<clinit>(HibernateUtil.java:9)
at com.hibernate.util.HibernateConfig.main(HibernateConfig.java:22)
Caused by: org.hibernate.MappingException: An AnnotationConfiguration instance is required to use <mapping/>
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1597)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1552)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1531)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1505)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1425)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1411)
at com.hibernate.util.HibernateUtil.buildSessionFactory(HibernateUtil.java:14)
… 2 more

Solution: Whenever we are using Annotations in our pojo class instead of hbm files we need to use Annotation configuration instead of normal configuration

For normal hbm files : This is how we instantiate Configuration. Continue reading

Apr 30

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder"

SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder”.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread “main” java.lang.NoClassDefFoundError: javax/persistence/EntityListeners
at org.hibernate.cfg.annotations.reflection.JPAMetadataProvider.getDefaults(JPAMetadataProvider.java:96)
at org.hibernate.annotations.common.reflection.java.JavaReflectionManager.getDefaults(JavaReflectionManager.java:226)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1355)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1826)
at employee.EmpTest.main(EmpTest.java:10)
Caused by: java.lang.ClassNotFoundException: javax.persistence.EntityListeners
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
… 5 more 

You will get this exception mostly when you forget to add slf4j-log4j.jar. When i added this slf4j-log4j12-1.5.6.jar my issue got resolved.