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!
|