I have an application working with the standard Hibernate JPA and Liquibase to generate db. I use H2 for testing and PostgreSQL at startup.
My problem is that I cannot get this setting to work well for primary keys with sequence generation.
When I have an object identifier, for example:
@Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id;
and use Liquibase to create the database, for example:
<column name="id" type="BIGINT" autoIncrement="true" incrementBy="1"> <constraints nullable="false" primaryKey="true" /> </column>
it works fine in H2, but for PostgreSQL Hibernate complains that it is:
"Missing sequence or table: hibernate_sequence"
I can fix this for PostgreSQL by changing the JPA @GeneratedValue to something like:
@Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "text_id_seq") @SequenceGenerator(name = "text_id_seq", sequenceName = "text_id_seq", allocationSize = 1) private Long id;
But now the H2 sequence will not match the expected Hibernate.
There seems to be no easy way to make sure that Liquibase is a sequence with a specific name. What can I do to make this setting work?
It seems to me that I am currently working
- Liquibase.version 2.0.4
- hibernate 4.1.7
- postgres driver 9.1-901.jdbc3
- postgres 9.2.1 (at least locally)
- h2 1.3.168
source share