Hi to all!
Sorry for the newbie question, but I have a problem with a OneToOne relationship.
I have this situation in a legacy DB that i can't modify:
A(fieldOne, fieldTwo, x) PK
foo
B(fieldOne, foo, y) PK
The OneToOne relationship that I have to implement is on:
A.foo=B.fooThe java code is:
Code:
@Entity
@Table(name = "A")
public class A implements java.io.Serializable {
private AId id; // it contains 'fieldOne', 'fieldTwo' and 'x'
private int foo;
private B b; // 1-to-1 relationship with B
// .. code ..
@OneToOne(mappedBy="a", targetEntity=B.class)
public B getB(){ ... }
public void setB(B b){ ... }
Code:
@Entity
@Table(name = "B", uniqueConstraints = @UniqueConstraint(columnNames = "ID"))
public class Bimplements java.io.Serializable {
private B BId; // it contains 'fieldOne', 'foo' and 'y'.
private A a; // 1-to-1 relationship with A
// .. code ..
@OneToOne(targetEntity=A.class)
@JoinColumn(name="FOO") // the name of the property foo in the table A.
public Ress getA() { ... }
public void setA(A a){ ... }
But this implementation raises:
Exception in thread "main" org.hibernate.TypeMismatchException: Provided id of the wrong type. Expected: class db.AId, got db.BIdAnd .. I simply don't understand why!
Thanks a lot!