| Author |
UniqueConstraint on foreign key (ManyToOne).
|
Gasan Guseynov
Ranch Hand
Joined: Jan 03, 2006
Posts: 67
|
|
Hi, guys.
Searched for the answer, but didn't find.
Here is what I have:
I think you inferred what is the problem. Yes, constraints aren't created. Just messed up with this.
|
 |
James Sutherland
Ranch Hand
Joined: Oct 01, 2007
Posts: 550
|
|
What error are you getting?
You Entity does not have an @Id, so is not valid. You seem to want both ManyToOne foreign keys to be the Id?
In JPA 2.0 you can just add @Id to both.
In JPA 1.0, it is more complex, see,
http://en.wikibooks.org/wiki/Java_Persistence/ManyToMany#Mapping_a_Join_Table_with_Additional_Columns
You object also seems to just be a many-to-many join table, if you mapped it as a ManyToMany, you would not need a class for it at all.
|
TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
|
 |
Gasan Guseynov
Ranch Hand
Joined: Jan 03, 2006
Posts: 67
|
|
Hi James.
Thanks for your answer it seems meaningful.
I'm sorry, I just forgot the @Id property, heh. So I have it. I want that 2 to be not ID, but simply unique. Unique constraint on (apple_id, watermelon_id) that are foreign keys. Stupid isn't it? But, for my misery, this is what I want.
|
 |
Gasan Guseynov
Ranch Hand
Joined: Jan 03, 2006
Posts: 67
|
|
By the way, thanks for the link. JPA 1.0 or 2.0 Just don't know, I always thought that JPA is JPA without versions. By the way, I'm using Hibernate, so maybe it doesn't matter what JPA version it is. It's simple annotations isn't it?
|
 |
 |
|
|
subject: UniqueConstraint on foreign key (ManyToOne).
|
|
|