[hibernate-issues] [Hibernate-JIRA] Created: (ANN-846) Infinite loop occurs while doing findById on a Parent domain Object having OneToMany relationship with child domain with composite primary key

RAMESH BABU NL (JIRA) noreply at atlassian.com
Wed Jun 24 17:15:33 EDT 2009


Infinite loop occurs while doing findById on a Parent domain Object having OneToMany relationship with child domain with composite primary key
----------------------------------------------------------------------------------------------------------------------------------------------

                 Key: ANN-846
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/ANN-846
             Project: Hibernate Annotations
          Issue Type: Improvement
    Affects Versions: 3.4.0.GA
         Environment: Hibernate Annotations 3.4.0.GA, HSqlDB and Oracle
            Reporter: RAMESH BABU NL
         Attachments: Organization.java, OrganizationApplications.java, OrganizationApplicationsPK.java

We are using Hibernate annotations version 3.4.0.G.A

We are establishing a OneToMany relationship using the annotation @OnetoMany for a Parent and Child domain objects
where the child domain has a composite primary key.



We have two domain objects 

Organization [Parent]
OrganizationApplications [Child]

We want to have a OnetoMany relationship between Organization and OrganizationApplications.

As shown below OrganizationApplications contains a composite primary key, of two columns(Organization Id, ApplicationId[foreignkey from other table called APPLICATIONS])


Organizations.java
-------------------

@OneToMany(targetEntity=gov.osc.enrollment.backend.domain.OrganizationApplications.class, cascade=CascadeType.ALL, fetch = FetchType.EAGER,
	           mappedBy="id.organization")
	private Set<OrganizationApplications> organizationApps = new HashSet<OrganizationApplications>();



OrganizationApplications.java
---------------------------------------------------------------------
public class OrganizationApplications extends EnvelopeInfo implements Serializable {

	private static final long serialVersionUID = 1L;
	
	@EmbeddedId
	private OrganizationApplicationsPK id;

	public OrganizationApplicationsPK getId() {
		return id;
	}

	public void setId(OrganizationApplicationsPK id) {
		this.id = id;
	}






OrganizationApplicationsPK.java
---------------------------------------------------------------------
@Embeddable
public class OrganizationApplicationsPK implements Serializable {

	private static final Long serialVersionUID = 1L;
	
	public OrganizationApplicationsPK() {
		super();
	}
	
	
	@ManyToOne
	@JoinColumn(name="APPLICATION_ID",nullable=false)
	private Applications application;

	@ManyToOne(targetEntity=gov.osc.enrollment.backend.domain.Organization.class, cascade=CascadeType.ALL)
	@JoinColumn(name="ORGANIZATION_ID", referencedColumnName="ORGANIZATION_ID", nullable=false, insertable=true, updatable=true)
	private Organization organization;


	public Applications getApplication() {
		return application;
	}

	public void setApplication(Applications application) {
		this.application = application;
	}

	public Organization getOrganization() {
		return organization;
	}

	public void setOrganization(Organization organization) {
		this.organization = organization;
	}

	@Override
	public boolean equals(Object o) {
		if (o == this) {
			return true;
		}
		if ( ! (o instanceof OrganizationApplicationsPK)) {
			return false;
		}
		OrganizationApplicationsPK other = (OrganizationApplicationsPK) o;
		return (this.getOrganization().getId() == other.getOrganization().getId())
			&& (this.getApplication().getId() == other.getApplication().getId());
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int hash = 17;
		hash = hash * prime + ((int) (this.getOrganization().getId() ^ (this.getOrganization().getId() >>> 32)));
		hash = hash * prime + ((int) (this.getApplication().getId() ^ (this.getApplication().getId() >>> 32)));
		return hash;
	}
}




Please see the attached java files for complete code and also the exception stack trace.



Questions:


1.  When we do a findById query on Organization table the system goes into infinite loop and never gets out .
	
	How ever we are able to insert a record in Organization and its child OrganizationApplications.



2.  In the Organization.java domain, if you notice we are using mappedby="id.organization". Is this a valid mapping ? 
       
       If not why does this parameter work for insert and not for a entityManager.findById, doing so leads to infinite loop.



-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list