This week's book giveaway is in the Artificial Intelligence forum.
We're giving away four copies of Pragmatic AI and have Noah Gift on-line!
See this thread for details.
Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Hibernate/JPA/PostGreSQL & hbm2ddl  RSS feed

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.
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,

Posts: 600
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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

Then, add this annotation to your id member:

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!