Initial SessionFactory creation failed-org-hibernate-MappingException-could-not-instantiate-id-generator

Initial SessionFactory creation failed-org-hibernate-MappingException-could-not-instantiate-id-generator

If you get below exception when using hibernate:

Initial SessionFactory creation failed.org.hibernate.MappingException: could not instantiate id generator
Exception in thread "main" java.lang.ExceptionInInitializerError
	at com.javahonk.HibernateUtil.buildSessionFactory(HibernateUtil.java:13)
	at com.javahonk.HibernateUtil.<clinit>(HibernateUtil.java:6)
	at com.javahonk.InsertData.main(InsertData.java:12)
Caused by: org.hibernate.MappingException: could not instantiate id generator
	at org.hibernate.id.IdentifierGeneratorFactory.create(IdentifierGeneratorFactory.java:98)
	at org.hibernate.mapping.SimpleValue.createIdentifierGenerator(SimpleValue.java:152)
	at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:192)
	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
	at com.javahonk.HibernateUtil.buildSessionFactory(HibernateUtil.java:10)
	... 2 more
Caused by: org.hibernate.MappingException: Dialect does not support sequences
	at org.hibernate.dialect.Dialect.getSequenceNextValString(Dialect.java:595)
	at org.hibernate.id.SequenceGenerator.configure(SequenceGenerator.java:65)
	at org.hibernate.id.IdentifierGeneratorFactory.create(IdentifierGeneratorFactory.java:94)
	... 6 more

 

This happens due to table where id is mentioned as primary key and generator class is not able to generate id automatically. To increment primary key id automatically use below class and this will make primary key increment automatically whenever you save the data to the table.

<id name="id" type="int">
            <column name="id" />
            <generator class="increment" />
</id>

Initial SessionFactory creation failed-org-hibernate-MappingException-could-not-instantiate-id-generator

Leave a Reply

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