This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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 Android Security Essentials Live Lessons this week in the Android 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: 5


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 ?
wood burning stoves
subject: Override id generation strategy [Spring] [Hibernate]
Similar Threads
data not persisted using hibernate spring integration
Spring/Hibernate - No Hibernate Session bound to thread, and configuration does not allow creation..
One to Many relationship Error. Please guide.
Hibernate & Spring performance problem
PersistentObjectException: detached entity passed to persist: