Hello,
We are having a problem with a one-to-many mapping using property-ref. We are getting a ClassCastException because the type of the property-ref column is not the same as the type of the PK. It looks to be a known issue from googling. Any insight on a workaround or a better way to do this mapping would be appreciated.
Background:
- 3 tables Account, User, UserAccount; One-to-many relationship between User and Account
- Join table UserAccount has the full primary key of User and part of the primary key of Account.
- One-to-many mapping for User to UserAccount which works as expected
- Property-ref attribute to model the relationship between UserAccount and Account.
- Found the following JIRA bug, indicating other people are experiencing the same issue with property-ref:
http://opensource.atlassian.com/project ... e/HHH-2052 I am using the following mapping files.<br/>
Account
<class name="com.model.Account" table="Account">
<composite-id class="com.model.VersionId"
mapped="false" name="id">
<key-property column="entity_id" name="entityId" type="java.lang.Long" />
<key-property column="entity_vers" name="version" type="java.lang.Long" />
</composite-id>
<property column="entity_id" name="entityId"
type="java.lang.Long" insert="false" update="false" />
<set name="userAccounts" cascade="none">
<key column="entity_id" property-ref="entityId"/>
<many-to-many class="com.model.UserAccount" column="acct_entity_id" property-ref="accountId"/>
</set>
</class>
User
<class name="com.model.User" table="User">
<composite-id class="com.model.VersionId"
mapped="false" name="id">
<key-property column="entity_id" name="entityId" type="java.lang.Long" />
<key-property column="entity_vers" name="version" type="java.lang.Long" />
</composite-id>
<property column="user_name" length="255" name="name"
type="java.lang.String" />
<set name="userAccounts" table="UserAccount">
<key>
<column name="entity_id" />
<column name="entity_vers" />
</key>
<one-to-many class="com.model.UserAccount" />
</set>
</class>
UserAccount
<class name="com.model.UserAccount"
table="UserAccount">
<composite-id class="com.model.UserAccountId"
mapped="false" name="id">
<key-property column="entity_id" name="userId" type="java.lang.Long" />
<key-property column="acct_entity_id" name="accountId"
type="java.lang.Long" />
<key-property column="entity_vers" name="userVersion"
type="java.lang.Long" />
</composite-id>
<property column="acct_entity_id" name="accountId"
type="java.lang.Long" insert="false" update="false"></property>
<many-to-one name="user"
class="com.model.User" insert="false"
update="false">
<column name="entity_id" />
<column name="entity_vers" />
</many-to-one>
<set name="accounts" cascade="none">
<key column="acct_entity_id" property-ref="acountId"/>
<many-to-many class="com.model.Account" column="entity_id" property-ref="entityId"/>
</set>
</class>
Thanks