Meaningless Drivel is fun!*
The moose likes Object Relational Mapping and the fly likes Composite Key Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Composite Key" Watch "Composite Key" New topic
Author

Composite Key

avihai marchiano
Ranch Hand

Joined: Jan 10, 2007
Posts: 342
Hey,

I have a composite key to user table.

so i have class for the composite-id - UserID (first,second)

I have class XXX like this:
1- the same pk like user
2- many to one to user.

in the many-to-one to the user i use in joincolumns like this:
@JoinColumns( { @JoinColumn(name = "first",referencedColumnName="first", @JoinColumn(name = "second",referencedColumnName="second") })

i get an exception:
repeated column for column- first
The same clumns are PK and FK.

Can you please advice.
avihai marchiano
Ranch Hand

Joined: Jan 10, 2007
Posts: 342
The classes:

avihai marchiano
Ranch Hand

Joined: Jan 10, 2007
Posts: 342
The solution will be to use in "insertable=false"
like this:
@JoinColumns( { @JoinColumn(name = "first",referencedColumnName="first",insertable=false,updatable=false)
, @JoinColumn(name = "second",referencedColumnName="second",insertable=false,updatable=false) })
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Composite Key
 
Similar Threads
How to map ManyToOne relationship with Composite key?
How do I map composite primary key/foreign key
Mysql auto generated PK used for another table and JPA
Could not determine type for: java.util.Set
@PrimaryKeyJoinColumn: no insertable and no updatable