MappingException AnnotationConfiguration instance required

MappingException AnnotationConfiguration instance required

Caused by: org.hibernate.MappingException: An AnnotationConfiguration instance is required to use

Exception in thread "main" java.lang.ExceptionInInitializerError
    at com.javahonk.util.HibernateUtil.buildSessionFactory(HibernateUtil.java:14)
    at com.javahonk.util.HibernateUtil.<clinit>(HibernateUtil.java:7)
    at com.javahonk.OneToOneInsert.main(OneToOneInsert.java:16)
Caused by: org.hibernate.MappingException: An AnnotationConfiguration instance is required to use <mapping class="com.javahonk.bean.Person"/>
    at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1692)
    at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1647)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1626)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1600)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1520)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1506)
    at com.javahonk.util.HibernateUtil.buildSessionFactory(HibernateUtil.java:11)
    ... 2 more

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();

Leave a Reply

Your email address will not be published. Required fields are marked *