You might have encountered this exception while mapping your POJO classes to tables in hibernate.
Solution:
If you see above exception it means you are not loading configuration from AnnotationConfiguration please load your configuration as below:
For loading configuration from XML file we use below code:
Exception:
SessionFactory creation failed.org.hibernate.MappingException: An AnnotationConfiguration instance is required to use <mapping class="com.javacodegeeks.enterprise.hibernate.Student"/> Exception in thread "main" java.lang.ExceptionInInitializerError at com.javacodegeeks.enterprise.hibernate.utils.HibernateUtil.buildSessionFactory(HibernateUtil.java:17) at com.javacodegeeks.enterprise.hibernate.utils.HibernateUtil.<clinit>(HibernateUtil.java:8) at com.javacodegeeks.enterprise.hibernate.Test.main(Test.java:14) Caused by: org.hibernate.MappingException: An AnnotationConfiguration instance is required to use <mapping class="com.javacodegeeks.enterprise.hibernate.Student"/> at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1524) at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1479) at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1458) at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1432) at org.hibernate.cfg.Configuration.configure(Configuration.java:1352) at org.hibernate.cfg.Configuration.configure(Configuration.java:1338) at com.javacodegeeks.enterprise.hibernate.utils.HibernateUtil.buildSessionFactory(HibernateUtil.java:13)
Solution:
If you see above exception it means you are not loading configuration from AnnotationConfiguration please load your configuration as below:
return new AnnotationConfiguration().configure().buildSessionFactory();
For loading configuration from XML file we use below code:
return new Configuration().configure().buildSessionFactory();
Comments
Post a Comment