Community
Participate
Working Groups
I've got a one-to-one relationship between the entities Course and Material. The relationship is annotated as follows: @Entity @Table(name = "TMP_COURSE") public class Course { ... @PrimaryKeyJoinColumn @OneToOne(cascade = CascadeType.PERSIST, optional=true) public Material getMaterial() { return material; } ... } @Entity @Table(name = "TMP_MATERIAL") public class Material { ... @Id @Column(name = "COURSE_ID") public long getCourseId() { return m_id; } @OneToOne(mappedBy = "material") public Course getCourse() { return course; } @PrePersist public void prePersist() { m_id = course.getCourseId(); } ... } EclipseLink's forward mapper generates a FK constraint from TMP_COURSE to TMP_MATERIAL.COURSE_ID. The constraint is generated although the relationship is annotated as optional. Inserting a Course without a Material fail with a FK constraint violation.
Created attachment 167700 [details] repro for this issue and workaround for issues in TestList The issue can be reproduced by jpa/eclipselink.jpa.wdf.test - org.eclipse.persistence.testing.tests.wdf.jpa1.relation.TestPrimaryKeyCoinColumn As a workaround for this issue, in TestList a Material ia persisted along with a Course
repro and workaround for TestList checked in at #7189 tested on MySQL reviewed by Andreas
Setting initial priority.
Created attachment 186184 [details] Proposed changes
Created attachment 186214 [details] Updated patch after review from Gordon Yorke
Changes submitted. Reviewed by: Gordon Yorke Tests: New test ( testOptionalPrimaryKeyJoinColumnRelationship) added to the DDLGenerationJUnitTestSuite to test. All tests pass (full regression test suite and extended jpa test suite)
Created attachment 186370 [details] activate the test for this issue Tests on MaxDB -> OK
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink