• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate/JPA/PostGreSQL & hbm2ddl

 
Eric Nielsen
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Has anyone gotten the following technologies to work properly together:
Hibernate as a JPA provider, backed by PostGreSQL 8.2 using when using hbm2ddl="auto"

I'm using DbUnit to provide some unit tests of the DAO layer of my application. Before I was trying to use hbm2ddl=auto, I had a working application and complete set of service layer DAO unit tests with DbUnit.

The main problems when using HBM2DDL
a) foreign keys don't end up with the ON DELETE CASCADE rules, even when I have cascade = {CascadeType.REMOVE} set on the association, causing the database purge/re-init by DbUnit to fail. (I know DbUnit says it will tear down in reverse order as setup, but it doesn't seem to be honoring that

b) the Primary key generation doesn't work seem to work. Before I had declared by primary keys as "serials" which in PostGreSQL speak would create a sequence and hook up a default for the column to pull from the sequence.. HBM2DDL creates the column, and creates the sequence, but doesn't establish the default rule.

Everything is done with annotations.
 
Mathieu Ruellan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you find a solution?

I've got the same problem with Hibernate 3.2.5ga (Maven repository).

Best regards,

 
John de Michele
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eric:

To do the primary key generation, add this annotation to your class defintion:

Then, add this annotation to your id member:

John.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic