This week's book giveaway is in the JDBC forum.
We're giving away four copies of Make it so: Java DB Connections & Transactions and have Marcho Behler on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Override id generation strategy [Spring] [Hibernate] Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Override id generation strategy [Spring] [Hibernate]" Watch "Override id generation strategy [Spring] [Hibernate]" New topic

Override id generation strategy [Spring] [Hibernate]

Eric Cornely

Joined: Aug 03, 2011
Posts: 9


I'm working on a project with Spring 2.5.6 and Hibernate 3.6.3. In every environment we're using sequences to generate Integer id for all our entities so :

But in my unit tests I'd like to use an in memory database like HSQL-DB and use an auto_increment so I would need to replace it by @GeneratedValue(strategy=GenerationType.IDENTITY).

How can I override that annotation only for unit tests ?

I'm already having a different spring configuration so I probably should be able to initialize a session factory that read XML definitions instead of annotations but how ?

Here is the spring configuration for my sessionFactory :

It's seems that I can easily override it according to that : but how could I configure spring to configure hibernate so that it reads those files ?
I agree. Here's the link:
subject: Override id generation strategy [Spring] [Hibernate]
It's not a secret anymore!