Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Infinite loop with self-referencing bi-directional relationship
Infinite loop with self-referencing bi-directional relationship [message #1022812] Fri, 22 March 2013 11:11 Go to next message
Micha-Jamie Guthmann is currently offline Micha-Jamie Guthmann
Messages: 13
Registered: October 2012
Junior Member
Hello I'm using Texo to generate JPA annotated code and there seems to be a problem when I have a Class referencing itself.
This is the stack trace that I get
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerNewObjectForPersist(UnitOfWorkImpl.java:4171)
    at org.eclipse.persistence.mappings.ObjectReferenceMapping.cascadeRegisterNewIfRequired(ObjectReferenceMapping.java:941)
    at org.eclipse.persistence.mappings.ObjectReferenceMapping.cascadeRegisterNewIfRequired(ObjectReferenceMapping.java:917)
    at org.eclipse.persistence.internal.descriptors.ObjectBuilder.cascadeRegisterNewForCreate(ObjectBuilder.java:1943)
    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerNewObjectForPersist(UnitOfWorkImpl.java:4171)
    at org.eclipse.persistence.mappings.ObjectReferenceMapping.cascadeRegisterNewIfRequired(ObjectReferenceMapping.java:941)
    at org.eclipse.persistence.mappings.ObjectReferenceMapping.cascadeRegisterNewIfRequired(ObjectReferenceMapping.java:917)
    at org.eclipse.persistence.internal.descriptors.ObjectBuilder.cascadeRegisterNewForCreate(ObjectBuilder.java:1943)
    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerNewObjectForPersist(UnitOfWorkImpl.java:4171)
    at org.eclipse.persistence.mappings.ObjectReferenceMapping.cascadeRegisterNewIfRequired(ObjectReferenceMapping.java:941)
    at org.eclipse.persistence.mappings.ObjectReferenceMapping.cascadeRegisterNewIfRequired(ObjectReferenceMapping.java:917)
    at org.eclipse.persistence.internal.descriptors.ObjectBuilder.cascadeRegisterNewForCreate(ObjectBuilder.java:1943)

This goes on and on always the same 4 lines
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerNewObjectForPersist(UnitOfWorkImpl.java:4171)
at org.eclipse.persistence.mappings.ObjectReferenceMapping.cascadeRegisterNewIfRequired(ObjectReferenceMapping.java:941)
at org.eclipse.persistence.mappings.ObjectReferenceMapping.cascadeRegisterNewIfRequired(ObjectReferenceMapping.java:917)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.cascadeRegisterNewForCreate(ObjectBuilder.java:1943)

This is the generated Resource class. It has a reference isPartofResource and its "counterpart" is EReference.
/**
 * A representation of the model object '<em><b>Resource</b></em>'. <!--
 * begin-user-doc --> <!-- end-user-doc -->
 * 
 * @generated
 */
@Entity(name = "de_raven_rml_resourcemodel_Resource")
public class Resource extends Identifiable {

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	@OneToOne(cascade = { CascadeType.MERGE, CascadeType.PERSIST,
			CascadeType.REFRESH }, mappedBy = "isPartofResource")
	private Resource eReference = null;
	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	@OneToOne(cascade = { CascadeType.ALL })
	private Resource isPartofResource = null;
	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	@Basic()
	private String name = null;

	/**
	 * Returns the value of '<em><b>EReference</b></em>' feature.
	 * 
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @return the value of '<em><b>EReference</b></em>' feature
	 * @generated
	 */
	public Resource getEReference() {
		return eReference;
	}

	/**
	 * Sets the '{@link Resource#getEReference() <em>EReference</em>}' feature.
	 * 
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @param the
	 *            new value of the '{@link Resource#getEReference() EReference}'
	 *            feature.
	 * @generated
	 */
	public void setEReference(Resource newEReference) {
		eReference = newEReference;
	}

	/**
	 * Returns the value of '<em><b>isPartofResource</b></em>' feature.
	 * 
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @return the value of '<em><b>isPartofResource</b></em>' feature
	 * @generated
	 */
	public Resource getIsPartofResource() {
		return isPartofResource;
	}

	/**
	 * Sets the '{@link Resource#getIsPartofResource()
	 * <em>isPartofResource</em>}' feature.
	 * 
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @param the
	 *            new value of the '{@link Resource#getIsPartofResource()
	 *            isPartofResource}' feature.
	 * @generated
	 */
	public void setIsPartofResource(Resource newIsPartofResource) {
		isPartofResource = newIsPartofResource;
	}

	/**
	 * Returns the value of '<em><b>name</b></em>' feature.
	 * 
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @return the value of '<em><b>name</b></em>' feature
	 * @generated
	 */
	public String getName() {
		return name;
	}

	/**
	 * Sets the '{@link Resource#getName() <em>name</em>}' feature.
	 * 
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @param the
	 *            new value of the '{@link Resource#getName() name}' feature.
	 * @generated
	 */
	public void setName(String newName) {
		name = newName;
	}

	/**
	 * A toString method which prints the values of all EAttributes of this
	 * instance. <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	@Override
	public String toString() {
		return "Resource " + " [name: " + getName() + "]";
	}
}


If I delete one of the references or both of them I have no issues. Is this a known issue, am I doing something wrong, or is something else to blame?

Best regards


Re: Infinite loop with self-referencing bi-directional relationship [message #1027051 is a reply to message #1022812] Tue, 26 March 2013 10:02 Go to previous message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

I can't see how this could occur.

How big/deep is the the set of objects? Check that your eReference reference the same identical instance as isPartofResource.

Setting logging to finest may also help.


James : Wiki : Book : Blog : Twitter
Previous Topic:[RESOLVED] How to Query "nextval('sequence_name');" in EclipseLink
Next Topic:metamodel with two data sources using annotations
Goto Forum:
  


Current Time: Mon Jul 28 02:28:07 EDT 2014

Powered by FUDForum. Page generated in 0.02395 seconds