-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: ClassCastException with property-ref
PostPosted: Wed May 18, 2011 9:56 am 
Newbie

Joined: Thu May 12, 2011 4:26 pm
Posts: 2
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


Top
 Profile  
 
 Post subject: Re: ClassCastException with property-ref
PostPosted: Tue May 31, 2011 12:07 am 
Newbie

Joined: Mon May 30, 2011 11:51 pm
Posts: 1
Hello,
I have a very similar problem with Hibernate 3.3.2.GA, when I merge ClazzTwo objects whith a new ClazzOne attribute

Code:
<class class="ClazzOne">
  <composite-id>
    <key-property name="one_attr1" column="OCOL1"/>
    <key-property name="one_attr2" column="OCOL2"/>
  </composite-id>

  <property name="one_attr3" column="OCOL3"/>
</class>

<class class="ClazzTwo">
    <id name="two_attr1" column="TCOL1"/>
    <many-to-one name="two_attr2" column="TCOL2" property-ref="one_attr3" class="ClazzOne" />
</class>


I have an IllegalArgumentException... Seems to be a bug not resolved since a long time.
I have to deal legacy tables; still haven't found a solution.

see:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3601
http://opensource.atlassian.com/projects/hibernate/browse/HHH-4014
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2432


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.