-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: how to override an identity attribute/sequence?
PostPosted: Thu Oct 28, 2010 5:58 am 
Newbie

Joined: Thu Oct 28, 2010 5:01 am
Posts: 1
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.