This is an unusual mapping. My gut feeling is that it is not a valid
mapping, but I don't see anything in the spec that would indicate it is

Here is the mapping:

public class Product {
   @Column(name = "id")
   private int id;

   @OneToOne(cascade = CascadeType.ALL)
   @JoinColumn(name = "id", referencedColumnName = "productId",
insertable = false, updatable = false)
   private ProductInfo productInfo;


public class ProductInfo{
   private int id;

   @Column(name = "productId", unique = true, updatable = false)
   private int productId;

Hibernate ignores referencedColumnName = "productId" and assumes that
Product and ProductInfo share the same ID value.
When the IDs are not the same, Product#productInfo will be null.

It seem to me that the foreign key column should be
ProductInfo#productId and should reference Product#id, but this
doesn't make sense
for a unidirectional one-to-one owned by Product.

IMO, a bidirectional @OneToOne with ProductInfo owning the association
would make more sense.

A test case can be found at [1]

Is the mapping invalid, or is this a bug in Hibernate?

hibernate-dev mailing list

Reply via email to