Tricky OneToOne mapping [message #646334] |
Thu, 23 December 2010 11:49 |
Matti Hansson Messages: 68 Registered: July 2009 |
Member |
|
|
Hi!
I have two classes, A and B, with a one to one relationship. Both classes have a primary key "OBJECT_ID", but they are joined by two other fields that comprises a composite key: "ID" and "ID_NUMBER".
The code thus far:
@Entity
public class A {
@Id
@Column(name = "OBJECT_ID")
private String objectId;
@OneToOne(mappedBy = "a")
private B b;
...
}
@Entity
public class B {
@Id
@Column(name = "OBJECT_ID")
private String objectId;
@OneToOne
@JoinColumns({
@JoinColumn(name = "ID", referencedColumnName = "ID", insertable = false, updatable = false),
@JoinColumn(name = "ID_NUMBER", referencedColumnName = "ID_NUMBER", insertable = false, updatable = false)
})
private A a;
...
}
So far so good. Now here's the tricky part: in some cases A and B are supposed to be joined even though their ID_NUMBERs don't match. This happens when A.ID = B.ID and B.ID_NUMBER = "999". At that time ID is unique on its own and A's ID_NUMBER is "1".
I have no idea how to accomplish this. Maybe through some customizer of some kind? Please help!
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02068 seconds