Search code examples
javaunit-testingplayframeworkfixtures

Is it possible to have the database ids loaded from a fixture start at a certain number?


I'm working with the Play Framework 2.2.1, for Java. I would like to have my fixtures, for my unit tests, have all the tables start their id counting at over 200.

The reason being this: Compare non-primitive Long values 127 and 128

Googling it gives a bunch of "best practice" articles, non of which include this option.

So I'm wondering if it's possible.

EDIT: To clarify, this would be for the unit tests only, not for the working environment. The unit tests are loaded via fixtures. Every test can have a different fixture, meaning the db gets wiped for ever test, meaning it would have to be done for every single table in the database on the loading of the fixture.

The Play Framework uses ebean as an abstraction layer. Play uses the H2 database for unit testing in memory.

EDIT: I ended up fixing it with a regular connection to H2. Ebeean does not seem to support this.


Solution

  • Yes it is (with most dbms at least). This sql statement works for MySQL: ALTER TABLE <table_name> AUTO_INCREMENT = 200;

    This one works for H2: ALTER TABLE <table_name> ALTER COLUMN <column_name> RESTART WITH 1