GeneratedValue on SecondaryTable [message #728047] |
Thu, 22 September 2011 09:00  |
Eclipse User |
|
|
|
Hi,
I've an entity there is split in two tables. Both tables have an ID. How can I automatically generate the second ID with a sequence ? I've always following error :
Class [class Person] has two @GeneratedValues: for fields [PERSON.ID] and [PERSON_ADDRESS.ID]. Only one is allowed.
My Code look like :
@Entity
@Table(name = "PERSON")
@SecondaryTable(name = "PERSON_ADDRESS", pkJoinColumns = @PrimaryKeyJoinColumn(name = FK_PERSON")
public class Person {
@SequenceGenerator(name = "Seq1", sequenceName = "SEQ1", allocationSize = 1)
@Id
@GeneratedValue(generator = "Seq1")
private Long id;
private String name;
@SequenceGenerator(name = "Seq2", sequenceName = "SEQ2", allocationSize = 1)
@Column(name = "ID", table = "PERSON_ADDRESS")
@GeneratedValue(generator = "Seq2")
private Long addressId;
@Column(table = "PERSON_ADDRESS")
private String address;
// ... getter and setter
}
What can I do ?
Thanks for your help !
|
|
|
Re: GeneratedValue on SecondaryTable [message #728113 is a reply to message #728047] |
Thu, 22 September 2011 10:49  |
Eclipse User |
|
|
|
You can currently only have one @GeneratedValue. You could generate the second id in your app, or in the PrePersist event, or possibly in a trigger.
It may be best to model the Address as another class, not a secondary table. Then it can have its own id.
|
|
|
|
Powered by
FUDForum. Page generated in 0.07788 seconds