-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Resetting sequence generators for unittesting
PostPosted: Fri Apr 13, 2012 8:43 am 
Newbie

Joined: Fri Apr 13, 2012 8:27 am
Posts: 1
We've defined a unique Id field with the following annotations:
@Id
@GeneratedValue(generator = "hibseq", strategy = GenerationType.TABLE)
@GenericGenerator(name = "hibseq", strategy = "enhanced-table", parameters = {
@Parameter(name = "table_name", value = "sequence_generator"),
@Parameter(name = "value_column_name", value = "sequence_next_hi_value "),
@Parameter(name = "segment_column_name", value = "sequence_name "),
@Parameter(name = "prefer_entity_table_as_segment_value", value = "true"),
@Parameter(name = "increment_size", value = "100") })
@Column(name = "id")


And defined the new generator mappings in persistence.xml:
<property name="hibernate.id.new_generator_mappings" value ="true"/>

For unittesting we're using DBUnit to prepopulate the database including the sequence_generator table with it's appropriate rows for each of the tables. When keeping the same EntityManagerFactory the table values that have been reset as part of the DBUnit reload between test runs doesn't reset the counter value for the next Id. Subsequent inserts will continue on from the last value assigned by the generator rather than the value reset by DBUnit. Is there any way of resetting a generator back to the database version? Another option for testing only might be to recreate the EntityManagerFactory for each test but this seems like a bad strategy to rebuild each time.

Thanks!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.