File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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 ?
I agree. Here's the link:
subject: Override id generation strategy [Spring] [Hibernate]
Similar Threads
data not persisted using hibernate spring integration
One to Many relationship Error. Please guide.
PersistentObjectException: detached entity passed to persist:
Spring/Hibernate - No Hibernate Session bound to thread, and configuration does not allow creation..
Hibernate & Spring performance problem