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:
Exception in thread "main" java.lang.NullPointerException
at org.hibernate.cfg.OneToOneSecondPass.doSecondPass(OneToOneSecondPass.java:135)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1127)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:296)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1283)
at com.javatpoint.Test.main(Test.java:13)

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 failed.org.hibernate.MappingException: An AnnotationConfiguration

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

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

78 total views, 1 views today

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

Problem:

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.

Solution: 

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:

Solution:

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