Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Override id generation strategy [Spring] [Hibernate]
PostPosted: Mon Apr 30, 2012 2:50 am 
Newbie

Joined: Mon Apr 30, 2012 2:19 am
Posts: 1
Hello,

I'm developping a project with a lot of Hibernate entities that are supposed to be persisted in Oracle but for unit tests we are using HSQLdb.

The problem I'm facing is that in HSQLdb we're not able to use sequences and trigger the same way as in oracle and we'd like to use simple auto_increment for primary key id.

Each entity has a id definition like this one :

Code:
@Entity
@SequenceGenerator(name = "seq", sequenceName = "TRADE_SEQ", allocationSize = 1)
@Table(name = "TRADE")
public class Trade{
    @Id
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seq") //TODO Override that definition for unitTest using HSQLDB auto_increment
    private Integer id;
//...


My problem is that I'd like to override just the @GeneratedValue during unit tests. I currently created each hbm.xml file for each entity and overridden just that GeneratedValue annotation but this leads to a huge maintenance work.

Our unit tests are run in a spring environnement configured like that :

Code:
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="packagesToScan" value="be.ecornely.entity" />
        <property name="mappingResources">
            <list>
                <value>entity/Trade.hbm.xml</value>
                <value>entity/TradeDetail.hbm.xml</value>
                <!-- ...-->
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
                <prop key="hibernate.hbm2ddl.auto">none</prop>
            </props>
        </property>
    </bean>


Is there a solution to override just the @GeneratedValue without having to use full hbm.xml files ?

I read:http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html/xml-overriding.html but haven't found a way to use that kind of file in my spring-created SessionFactory.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.