Hi all,
I am trying to override an identity attribute a.id in two subclasses b and c. The problem is that I want to use the same database sequence (id_seq) for both b.id and c.id attributes. I came up with something below, which does not work.
public class a { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) protected long id; ... }
public class b extends a { @SequenceGenerator(name="b_seq_generator", sequenceName="id_seq") @Id @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="b_seq_generator") long id; public long getId() { ... } public void setId(long id) { ... } ... }
public class c extends a { @SequenceGenerator(name="c_seq_generator", sequenceName="id_seq") @Id @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="c_seq_generator") long id; public long getId() { ... } public void setId(long id) { ... } ... }
"@GeneratedValue(strategy = GenerationType.IDENTITY)" generates a sequence name by using the class names (There are other classes that extend a. I want them to stay as they are.) as default and hibernate insists on using those sequences instead of my "id_seq" sequence.
I would really appreciate it if someone could help me out.
Kind Regards Fuat
|