This is my situation:
Code:
/**
* @hibernate.class
*/
public class Person {
}
/**
* @hibernate.class
*/
public class Organisation {
/**
* @hibernate.set cascade="all" lazy="true" inverse="true"
* @hibernate.collection-key column="organisationId"
* @hibernate.collection-one-to-many class="Person"
*/
public Set getEmployees() {
}
}
/**
* @hibernate.class
*/
public class ConceptOrganisation {
/**
* @hibernate.component class="Organisation"
*/
public Organisation getOrganisation() {
}
}
Hibernate mapping file of conceptorganisation:
<hibernate-mapping>
<class name="ConceptOrganization">
<id name="id" column="id" type="java.lang.Long">
<generator class="native" />
</id>
<component name="organisation" class="Organisation">
<set name="employees">
<key column="organizationId" />
<one-to-many class="Person" />
</set>
</component>
</class>
</hibernate-mapping>
Now i have a Organisation with ID = 1 and a ConceptOrganisation with ID = 1.
Organisation 1 has relation to 3 person objects in the database.
The problem pops up when i get the conceptorganisation with id = 1 from the database. Suddenly also the 3 person objects appear in my conceptorganisation.
The organisation component inside the conceptorganisation may have a list of person-objects, but there should be no relation between the person-object and the conceptorganisation.
How can i overcome this problem. I don't want to copy all properties from the organisation object into the conceptorganisation object.