-->
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.  [ 6 posts ] 
Author Message
 Post subject: java.lang.ClassCastException: ...BackrefPropertyAccessor$1
PostPosted: Thu Nov 08, 2007 10:06 pm 
Newbie

Joined: Wed Nov 01, 2006 4:11 pm
Posts: 7
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.1

Mapping documents:
<list name="values" cascade="all-delete-orphan" lazy="true" inverse="false" >
<key column="scale_id" not-null="true"/>
<list-index column="value_position" />
<one-to-many entity-name="scale_value" />
</list>

The above mapping gives this error:

java.lang.ClassCastException: org.hibernate.property.BackrefPropertyAccessor$1
at org.hibernate.type.LongType.set(LongType.java:42)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:83)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:65)
at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1513)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1575)
at org.hibernate.loader.Loader.doQuery(Loader.java:661)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2144)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2028)
at org.hibernate.loader.Loader.list(Loader.java:2023)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:95)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)

If I remove the not-null constraint from the <key> element, it works fine.

I am simply retrieving all instances of the value classing using a criteria.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 09, 2007 6:38 am 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
Does your scale_value entity have a mapping to its parent or to its parent ID? Looks like hibernate trying to set a long but is given the parent object instead.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 09, 2007 10:36 am 
Newbie

Joined: Wed Nov 01, 2006 4:11 pm
Posts: 7
Hey. Yeah, there's a mapping from the values entity back to the owning entity:

<many-to-one name="scale" entity-name="scale" insert="false" update="false" not-null="true">
<column name="scale_id"/>
</many-to-one>

(The mapping snippet from my original post was from scale to value)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 09, 2007 11:33 am 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
Your situation is almost straight out of the hibernate docs:
Code:
<class name="Address">
   <id name="id"/>
   ...
   <list name="people">
      <key column="addressId" not-null="true"/>
      <list-index column="peopleIdx"/>
      <one-to-many class="Person"/>
   </list>
</class>

<class name="Person">
   <id name="id"/>
   ...
   <many-to-one name="address"
      column="addressId"
      not-null="true"
      insert="false"
      update="false"/>
</class>


Try removing some of the extra attributes from the parent mapping (i.e. cascade="all-delete-orphan" lazy="true" inverse="false") to make yours closer to theirs.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 09, 2007 11:46 am 
Newbie

Joined: Wed Nov 01, 2006 4:11 pm
Posts: 7
Yeah, I did try that to no avail.

Same result if mapping is:

<!-- cascade="all-delete-orphan" lazy="true" inverse="false" -->
<list name="values">
<key column="scale_id" not-null="true" />
<list-index column="value_position" />
<one-to-many entity-name="scale_value" />
</list>

Which is almost verbatim from the book:

<list name="bids">
<key column="ITEM_ID" not-null="true"/>
<list-index column="BID_POSITION"/>
<one-to-many class="Bid"/>
</list>

Except the book uses class and I'm using entity-name.

My mapping from the list-member back to the owner is basically the same also:

(mine)
<many-to-one name="scale" entity-name="scale" insert="false" update="false" not-null="true">
<column name="scale_id"/>
</many-to-one>

(the Book's)
<many-to-one name="item" column="ITEM_ID" class="Item" not-null="true" insert="false" update="false" />

I guess I can try moving the column element into an attribute.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 09, 2007 5:05 pm 
Newbie

Joined: Wed Nov 01, 2006 4:11 pm
Posts: 7
This appears to happen when doing a criteria fetch for all the objects of a type, when that type is used as a list member on another object. Admittedly a pretty edge use case. In any case, if you really need to do that, you can avoid the Backref error by making the key to the list nullable (both in the mapping and in your DDL).


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.