Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 331331

Summary: Integrity constraint violation - no parent ...
Product: z_Archived Reporter: MK Maddy <rkumaresh>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: RESOLVED FIXED QA Contact:
Severity: major    
Priority: P2 CC: tom.ware
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description MK Maddy CLA 2010-11-29 07:39:54 EST
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
Comment 1 Tom Ware CLA 2010-12-01 10:31:48 EST
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;
Comment 2 MK Maddy CLA 2010-12-01 12:04:11 EST
(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;
Comment 3 Tom Ware CLA 2010-12-03 08:52:46 EST
Please post the code you use to create the objects, associate them and flush them.
Comment 4 Tom Ware CLA 2010-12-09 09:06:45 EST
Setting target and priority.  See the following page for the meanings of these fields:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines
Comment 5 MK Maddy CLA 2010-12-09 10:07:50 EST
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();
}
Comment 6 MK Maddy CLA 2010-12-09 10:09:22 EST
Working in version 2.2.0-M5
Comment 7 Eclipse Webmaster CLA 2022-06-09 10:23:48 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink