Category Archives: hibernate

Exception at org.hibernate.cfg.OneToOneSecondPass.doSecondPass(OneToOneSecondPass)

You might end up with this exception while doing your one to one ,or many to one relationship in hibernate.

Exception in thread "main" java.lang.NullPointerException
at org.hibernate.cfg.OneToOneSecondPass.doSecondPass(
at org.hibernate.cfg.Configuration.secondPassCompile(
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(
at org.hibernate.cfg.Configuration.buildSessionFactory(
at com.javatpoint.Test.main(

To fix correct this exception Check following :

1. Your one to one mapping bean is pointing to correct column.
2. You have configured both table correctly.

Once you have correct these your exception will go away.

77 total views, 1 views today

SessionFactory creation An AnnotationConfiguration

You might have encountered this exception while mapping your POJO classes to tables in hibernate.

SessionFactory creation 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(
at com.javacodegeeks.enterprise.hibernate.utils.HibernateUtil.<clinit>(
at com.javacodegeeks.enterprise.hibernate.Test.main(
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(
at org.hibernate.cfg.Configuration.parseSessionFactory(
at org.hibernate.cfg.Configuration.doConfigure(
at org.hibernate.cfg.Configuration.doConfigure(
at org.hibernate.cfg.Configuration.configure(
at org.hibernate.cfg.Configuration.configure(
at com.javacodegeeks.enterprise.hibernate.utils.HibernateUtil.buildSessionFactory(


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

78 total views, 1 views today

java.lang.ClassCastException: org.hibernate.type.StringType cannot be cast to org.hibernate.type.VersionType


Hibernate Tool While reverse engineering

Reason for this problem: In one of my table there was a field named version. Which Hibernate tool treated as field version and try to cast the same and it throws an exception because the type of the field was not what hibernate tool was expecting.


Open the hbm configuration file for corresponding table and change the configuration of that field from <version> to <property> .

86 total views, no views today

Hibernate dialects

DB2 – org.hibernate.dialect.DB2Dialect

HypersonicSQL – org.hibernate.dialect.HSQLDialect

Informix – org.hibernate.dialect.InformixDialect

Ingres – org.hibernate.dialect.IngresDialect

Interbase – org.hibernate.dialect.InterbaseDialect

Pointbase – org.hibernate.dialect.PointbaseDialect

PostgreSQL – org.hibernate.dialect.PostgreSQLDialect

Mckoi SQL – org.hibernate.dialect.MckoiDialect

Microsoft SQL Server – org.hibernate.dialect.SQLServerDialect

MySQL – org.hibernate.dialect.MySQLDialect

Oracle (any version) – org.hibernate.dialect.OracleDialect

Oracle 9 – org.hibernate.dialect.Oracle9Dialect

Progress – org.hibernate.dialect.ProgressDialect

FrontBase – org.hibernate.dialect.FrontbaseDialect

SAP DB – org.hibernate.dialect.SAPDBDialect

Sybase – org.hibernate.dialect.SybaseDialect

Sybase Anywhere – org.hibernate.dialect.SybaseAnywhereDialect

63 total views, no views today

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

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


You are missing a field annotated with @Id. Each @Enitity needs an @Id – this is the primary key in the database.

If you don’t want your entity to be persisted in a separate table, but rather be a part of other entities, you can use @Embeddable instead of @Entity.

56 total views, no views today