Community
Participate
Working Groups
Build Identifier: 2.2.0 Table A has self referencing foreign key which can be null. Table_A columns(ID, INTERNALOTHERID) ClassA @Id() private Long id; @OneToOne(fetch=FetchType.LAZY) @JoinColumn(name="INTERNALOTHERID") private Long internalOtherId; Scenario -------- 1. Create two records with internalOtherId referring to each other primary key ClassA(1,2) and ClassA(2,1) Issue : Internal Exception: java.sql.SQLException: Integrity constraint violation - no parent FK_Table_A_INTERNALOTHERID Reproducible: Always Steps to Reproduce: Table_A columns(ID, INTERNALOTHERID) 1. Create two records with internalOtherId referring to each other primary key 2. Flush both the records 3. Errors - java.sql.SQLException: Integrity constraint violation - no parent FK_Table_A_INTERNALOTHERID
Test case is incorrect. This mapping should reference ClassA instead of Long. Long cannot be the target of a 1-1 @OneToOne(fetch=FetchType.LAZY) @JoinColumn(name="INTERNALOTHERID") private Long internalOtherId;
(In reply to comment #1) > Test case is incorrect. This mapping should reference ClassA instead of Long. > Long cannot be the target of a 1-1 > > @OneToOne(fetch=FetchType.LAZY) > @JoinColumn(name="INTERNALOTHERID") > private Long internalOtherId; Sorry that was my mistake proving the wrong mapping. But still its a valid issue with the correct mapping, please find it below. Table_A columns(ID, INTERNALOTHERID) ClassA @Id() private Long id; @OneToOne(fetch=FetchType.LAZY) @JoinColumn(name="INTERNALOTHERID") private ClassA internalOtherId;
Please post the code you use to create the objects, associate them and flush them.
Setting target and priority. See the following page for the meanings of these fields: http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines
import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.OneToOne; import javax.persistence.Table; @Entity @Table(name="ClassA") public class ClassA { @Id() private Long id; @JoinColumn(name="INTERNALOTHERID") @OneToOne(fetch=FetchType.LAZY) private ClassA internalOther; public ClassA() { } public Long getId() { return this.id; } public void setId(Long id) { this.id = id; } public ClassA getInternalOther() { return this.internalOther; } public void setInternalOther(ClassA internalOther) { this.internalOther = internalOther; } } Test Case: ********** public void testClassA() throws Exception { ClassA one = new ClassA(); one.setId(Long.valueOf(100)); ClassA two = new ClassA(); two.setId(Long.valueOf(200)); two.setInternalOther(one); one.setInternalOther(two); getEntityManager().persist(one); getEntityManager().persist(two); getEntityManager().flush(); }
Working in version 2.2.0-M5
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink