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

Bug 332654

Summary: Null reference inserted for self-referencing entity instance
Product: z_Archived Reporter: Adrian Gygax <adrian.gygax>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: NEW --- QA Contact:
Severity: normal    
Priority: P2 CC: tom.ware
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Adrian Gygax CLA 2010-12-15 11:04:22 EST
Build Identifier: 20100218-1602 (Eclipselink 2.1.1)

I've got exactly the same problem as described in http://www.eclipse.org/forums/index.php?t=tree&th=124961&

Eclipselink should detect this special case and either not do a shallow commit or update the foreign key in a second query as it would do for other circular references.

Reproducible: Always

Steps to Reproduce:
See the newsgroup post http://www.eclipse.org/forums/index.php?t=tree&th=124961&
Comment 1 Tom Ware CLA 2010-12-17 09:26:09 EST
Please post, at least, a description of the problem in the bug.
Comment 2 Adrian Gygax CLA 2010-12-21 05:33:57 EST
Problem description:

I have the following:

@Entity
public class User {

@Id
@GeneratedValue(strategy = SEQUENCE)
@Column(name = "id", nullable = false, updatable = false)
private Long id = null;

@OneToOne
@JoinColumn(name = "created_by", updatable = false, nullable = false)
private User createdBy;

...

}

Then I persist it

User u = new User();
u.setCreatedBy(u);

em.persist(u);

As you see the user creator is himself.

I get the error of:

Caused by: org.postgresql.util.PSQLException: ERROR: null value in column
"created_by" violates not-null constraint


EclipseLink generates an SQL statement with CREATED_BY = NULL. This happens even if I manually set an ID for the User.
Comment 3 Tom Ware CLA 2010-12-23 11:43:02 EST
Setting target and priority.  See the following page for the meanings of these fields:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines
Comment 4 Eclipse Webmaster CLA 2022-06-09 10:35:52 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink