Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » GeneratedValue on SecondaryTable
GeneratedValue on SecondaryTable [message #728047] Thu, 22 September 2011 09:00 Go to next message
Alex Mising name is currently offline Alex Mising name
Messages: 5
Registered: September 2011
Junior Member
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 Go to previous message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

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.


James : Wiki : Book : Blog : Twitter
(no subject) [message #728129 is a reply to message #728047] Thu, 22 September 2011 10:49 Go to previous message
James is currently offline James
Messages: 272
Registered: July 2009
Senior Member
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.

--
James : http://wiki.eclipse.org/EclipseLink : http://en.wikibooks.org/wiki/Java_Persistence : http://java-persistence-performance.blogspot.com/
Previous Topic:Difference between EntityManager and SessionFactory
Next Topic:Difference between EntityManager and SessionFactory
Goto Forum:
  


Current Time: Sat Apr 19 18:29:14 EDT 2014

Powered by FUDForum. Page generated in 0.02266 seconds