Hi,

Does Hibernate support having both entities involved in a one-to-one
association own its side of the association when using
@PrimaryKeyJoinColumn?

My guess is that this is not supported by Hibernate. I just want to confirm.

For example:

@Entity
public class Employee {

    @EmbeddedId
    private CompositeKey id;

    @OneToOne(optional = false)
    @PrimaryKeyJoinColumns({
          @PrimaryKeyJoinColumn(name = "ID1", referencedColumnName = "ID1"),
          @PrimaryKeyJoinColumn(name = "ID2", referencedColumnName =
"ID2"), })
    })
    private EmployeeInfo employeeInfo;
    ...
}

@Entity
public class EmployeeInfo {

    @EmbeddedId
    private CompositeKey id;

    @OneToOne(optional = false)
    @PrimaryKeyJoinColumns({
          @PrimaryKeyJoinColumn(name = "ID1", referencedColumnName = "ID1"),
          @PrimaryKeyJoinColumn(name = "ID2", referencedColumnName =
"ID2"), })
    })
    private Employee employee;
 ...
}

In this particular case, the foreign keys have been deleted, so it's
possible to load and delete these entities.

An attempt to insert an entity on either side results in:
org.hibernate.PropertyValueException: not-null property references a null
or transient value

When converted to use @MapsId and @JoinColumns instead, Hibernate throws:
org.hibernate.MappingException: cyclic dependency in derived identities

Please let me know...

Thanks,
Gail
_______________________________________________
hibernate-dev mailing list
hibernate-dev@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/hibernate-dev

Reply via email to