3.0.5
Code:
<hibernate-mapping package="com.carma.console.maintenance.company">
<class name="RaasCompany" schema="respraas" table="COMPANY" lazy="true" mutable="false">
<!-- Meta attributes for code generation -->
<meta attribute="scope-class">public abstract</meta>
<meta attribute="scope-field">protected</meta>
<meta attribute="implement-equals">true</meta>
<meta attribute="extends">com.carma.console.BaseHibernateObject</meta>
<meta attribute="generated-class">com.carma.console.maintenance.company.model.AbstractRaasCompany</meta>
<!-- Id -->
<id name="companyKey" column="COMPANY_KEY" type="string">
<meta attribute="use-in-tostring">true</meta>
<generator class="assigned"></generator>
</id>
<property name="name" column="COMPANY_NAME" type="string" not-null="true" length="100">
<meta attribute="use-in-tostring">true</meta>
<meta attribute="use-in-equals">true</meta>
</property>
<many-to-one name="country" column="COUNTRY_KEY" class="com.carma.console.common.Country" not-null="true"></many-to-one>
<many-to-one name="orgCountry" column="ORG_COUNTRY_KEY" class="com.carma.console.common.Country" not-null="false"></many-to-one>
<property name="ModStamp" column="MOD_STAMP" type="date" not-null="false" length="7" />
<property name="ModFlag" column="MOD_FLAG" type="string" not-null="false" length="1" />
<property name="ModUser" column="MOD_USER" type="string" not-null="false" length="8" />
<joined-subclass name="RaasRepertoireOwner" schema="respraas" table="REPERTOIRE_OWNER" lazy="true">
<meta attribute="generated-class">com.carma.console.maintenance.company.model.AbstractRaasRepertoireOwner</meta>
<key column="REP_OWNER_KEY"></key>
<many-to-one name="raasProfitCenter" column="PROFIT_CENTER_KEY" class="com.carma.console.maintenance.company.RaasProfitCenter" />
<property name="modStamp" column="MOD_STAMP" type="date" not-null="false" length="7" />
<property name="modFlag" column="MOD_FLAG" type="string" not-null="false" length="1" />
<property name="prodRepOwner" column="IS_PROD_REP_OWNER" type="true_false" not-null="false" length="1" />
</joined-subclass>
<joined-subclass name="RaasProfitCenter" schema="respraas" table="PROFIT_CENTER" lazy="true" >
<meta attribute="generated-class">com.carma.console.maintenance.company.model.AbstractRaasProfitCenter</meta>
<key column="PROFIT_CENTER_KEY"></key>
<property name="modStamp" column="MOD_STAMP" type="date" not-null="false" length="7" />
<property name="modFlag" column="MOD_FLAG" type="string" not-null="false" length="1" />
<property name="modUser" column="MOD_USER" type="string" not-null="false" length="8" />
</joined-subclass>
</class>
</hibernate-mapping>
Hi,
I have a class 'RaasCompany' which has two subclasses 'RaasRepertoireOwner' and 'RaasProfitCenter'. We are using a table per subclass strategy, eg. we have a company, repertoireowner and profitcenter table.
The company with the key 1 could be a repertoire owner and at the same time it could be a profit center. There is also a n-1 relationship between repertoire owner and profitcenter. It can be the case that for the repertoire owner (company id=1) the profit center is the same company (also id=1).
Now when I load this repertoire owner the profit center also gets loaded but instead of loading a RaasProfitCenter class the already loaded RaasRepertoireOwner is taken from the session. This is because they same have the same id and the same rootEntityName.
I can solve my problem by adapting the org.hibernate.engine.EntityKey-classes equals and hashcode methods so that instead of the rootEntityName they use the entityName. Then the entity is not found in the session and loaded properly.
Now I am wondering:
-Did I miss something and I can achieve this more easily
-Is it a bad idea to change the equals and the hashcode method of the EntityKey class
As far as I understand for Hibernate an entity with the same id can not be two different sub-classes of the same parent-class. But this is exaclty what I need. Is this an unresonably requirement?
Any comment is appreciated.
Thanks,
Ronald