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.