Folks! I found a workaround in that way. As I wrote my original superclass was
@MappedSuperclass
abstract class IdentifiedEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
...
}
and recreate.sql
create table "user" (
user_id serial primary key,
...
);
create table meal (
meal_id serial primary key,
user_id int not null references "user"(user_id),
...
);
The fix is in strategy of @GeneratedValue(strategy = GenerationType.IDENTITY). Here is the renewed IdentifiedEntity:
@MappedSuperclass
abstract class IdentifiedEntity {
@Id
@SequenceGenerator(name = "seqgen", sequenceName = "sequencer")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seqgen")
private int id;
...
}
and recreate.sql
create sequence sequencer;
create table "user" (
user_id int primary key default nextval('sequencer'),
...
);
create table meal (
meal_id int primary key default nextval('sequencer'),
user_id int not null references "user"(user_id),
...
);
and refill.sql
...
alter sequence sequencer restart 1;
...
In my opinion there is a BUG in Hibernate, reproducing if @GeneratedValue(strategy = GenerationType.IDENTITY). |