# Derby AutoIncrement

**URL:** <https://forum.liquibase.org/t/derby-autoincrement/522>\
**Category:** General Discussion\
**Created:** [May 12, 2010, 11:32pm UTC](https://forum.liquibase.org/t/derby-autoincrement/522 "2010-05-12T23:32:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![eviljohn](https://avatars.discourse-cdn.com/v4/letter/e/c0e974/32.png) [@eviljohn](https://forum.liquibase.org/u/eviljohn)\
**Post date:** [May 12, 2010, 11:32pm UTC](https://forum.liquibase.org/t/derby-autoincrement/522/1 "2010-05-12T23:32:00Z")

</div>

Hi,

I’m trying to implement Liquibase with a derby database, and i’m running into a problem with our JPA inserts. Liquibase seems to produce the following SQL:

CREATE TABLE employee (id INT GENERATED BY DEFAULT AS IDENTITY&nbsp; NOT NULL, name VARCHAR(50) NOT NULL, CONSTRAINT PK\_EMPLOYEE PRIMARY KEY (id));

What I’m looking for this:

CREATE TABLE employee (id INT GENERATED ALWAYS AS IDENTITY&nbsp; NOT NULL, name VARCHAR(50) NOT NULL, CONSTRAINT PK\_EMPLOYEE PRIMARY KEY (id));

Is there anyway to do this with liquibase? I’m using the 2.0 RC1 due to issues with the 1.9.5.0 release.

Thanks!

---

<div class="post-metadata">

**Author:** ![nvoxland](https://avatars.discourse-cdn.com/v4/letter/n/87869e/32.png) [@nvoxland](https://forum.liquibase.org/u/nvoxland)\
**Post date:** [May 12, 2010, 11:32pm UTC](https://forum.liquibase.org/t/derby-autoincrement/522/2 "2010-05-12T23:32:00Z")

</div>

What is the problem you are running into.&nbsp; The only difference I thought was that ALWAYS did not allow you to specify an ID, even if you wanted to.&nbsp; For more flexibility I thought the BY DEFAULT option was better.&nbsp; If there are things that break due to BY DEFAULT I could change it if it made sense.

Since you are on 2.0, you can use the new plug-in system.&nbsp; You should be able to create a new class in a subpackage of “liquibase.ext” and extend liquibase.database.core.DerbyDatabase.&nbsp; Override getPriority and return a value higher than 10 and override the getAutoIncrementClause() method to return “GENERATED ALWAYS AS IDENTITY”

Nathan

---

<div class="post-metadata">

**Author:** ![eviljohn](https://avatars.discourse-cdn.com/v4/letter/e/c0e974/32.png) [@eviljohn](https://forum.liquibase.org/u/eviljohn)\
**Post date:** [May 12, 2010, 11:32pm UTC](https://forum.liquibase.org/t/derby-autoincrement/522/3 "2010-05-12T23:32:00Z")

</div>

Thanks for the heads-up on the ext mechanism, I’ll see if I can make that work.

The problem I’m having is I have JPA annotated objects defined with integers as primary keys, and they always have a value, which is causing problems when inserting our seed data into (or anything else for that matter) into the tables.

---

<div class="post-metadata">

**Author:** ![nvoxland](https://avatars.discourse-cdn.com/v4/letter/n/87869e/32.png) [@nvoxland](https://forum.liquibase.org/u/nvoxland)\
**Post date:** [May 12, 2010, 11:32pm UTC](https://forum.liquibase.org/t/derby-autoincrement/522/4 "2010-05-12T23:32:00Z")

</div>

I would have thought JPA would know that the id has the default value and that it should still insert without passing it.&nbsp; Interesting. Thanks for the heads up.&nbsp; I’ll think about what seems like the best default.

Nathan&nbsp;
