| Summary: | can't map optional one-to-one relationship using @PrimaryKeyJoinColumn | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Product: | z_Archived | Reporter: | Adrian Goerler <adrian.goerler> | ||||||||||
| Component: | Eclipselink | Assignee: | Guy Pelletier <guy.pelletier> | ||||||||||
| Status: | RESOLVED FIXED | QA Contact: | |||||||||||
| Severity: | minor | ||||||||||||
| Priority: | P2 | CC: | eclipselink.orm-inbox, guy.pelletier, sabine.heider, tom.ware | ||||||||||
| Version: | unspecified | ||||||||||||
| Target Milestone: | --- | ||||||||||||
| Hardware: | PC | ||||||||||||
| OS: | Windows Vista | ||||||||||||
| URL: | http://wiki.eclipse.org/Talk:EclipseLink/Bugs/309681#Optional_one-to-one_relationship_using_.40PrimaryKeyJoinColumn | ||||||||||||
| Whiteboard: | |||||||||||||
| Bug Depends on: | |||||||||||||
| Bug Blocks: | 309681 | ||||||||||||
| Attachments: |
|
||||||||||||
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 |
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.