Wednesday, November 10, 2010

SQLite Hibernate: Primary Keys and Foreign Keys on generated values

Here a little hint on defining the correct mapping for generated values and their relationships.

If the SQLiteDialect.class is used for the Hibernate dialect and the identity column string returns "integer".

When I generated the database table with
hibernate.hbm2ddl.auto=create
and then read it back with
hibernate.hbm2ddl.auto=validate
I ended up with corrupt foreign key relationships.


Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [orm-layer.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Wrong column type in APPLICATION for column APPLICATION_ID. Found: integer, expected: bigint
at Caused by: org.hibernate.HibernateException: Wrong column type in APPLICATION for column APPLICATION_ID. Found: integer, expected: bigint
at org.hibernate.mapping.Table.validateColumns(Table.java:284)
at org.hibernate.cfg.Configuration.validateSchema(Configuration.java:1130)
at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:139)
at org.hibernate.impl.SessionFactoryImpl.(SessionFactoryImpl.java:359)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1341)
at


Here the tip of my configuration: just make sure your generated values are "integer" by using the columnDefinition and both "create" and "validate" settings for hibernate.hbm2ddl.auto.

No comments:

Post a Comment