Search code examples
hibernateloopssequencederby

Derby Sequence Loop in junit test


I'm in trouble when using Derby with embedded driver (derby-10.9.1.0) and in-memory db in my JUNIT with Hibernate (hibernate-core-3.6.8.Final) environment.

I'm using annotations and using hbm2ddl to create my in-memory db.

Everything is working except when I try to use an sequence.

The sequence is created (it appears in the log), but when I try to add one entity (hibernate) with PK related to that sequence my code starts a infinite loop writing in each line:

Hibernate: values next value for app.SE_FERI

My db is created as:

jdbc:derby:memory:testdb;create=true

I'm using hbm2ddl inside my code, before the database use, as:

SchemaExport schemaExport = new SchemaExport(config);
schemaExport.drop(true, true);
schemaExport.create(true, true);

Some help !?


Solution

  • This problem occurres when the allocationSize of the sequence is set to 1. Setting it to a value > 1 worked for me.

    I know this thread is kinda old, but if anybody else has this problem, this could be the solution.

    Edit: spelling