-->
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.  [ 3 posts ] 
Author Message
 Post subject: many-to-one / one-to-many bidirectional - cannot load set
PostPosted: Fri Apr 15, 2011 11:02 am 
Newbie

Joined: Fri Apr 15, 2011 10:53 am
Posts: 2
Hi,

I've spent all the day searching for the mistake or some solution. Read all the available books/forums... Cannot understand what's happening.

Here's the situation:.
Mappings:
Code:
<hibernate-mapping default-access="property">
    <class name="com.sns.ukrsov.domain.Cartcontainer" table="cartcontainer" catalog="ukrsovcat" >
        <id name="cartId" type="string">
            <column name="cartId" length="128" not-null="true"/>
            <generator class="uuid" />
        </id>
        <property name=... skipped >
       
        <set name="cartitems" cascade="save-update,delete" inverse="true">
         <key column="parentCartid" not-null="true"/>
         <one-to-many class="com.sns.ukrsov.domain.Cartitems" />
      </set>
      
    </class>
</hibernate-mapping>

<hibernate-mapping default-access="property">
    <class name="com.sns.ukrsov.domain.Cartitems" table="cartitems" catalog="ukrsovcat" proxy="com.sns.ukrsov.domain.CartitemsIntf">
        <id name="itemid" type="string">
            <column name="itemid" length="128" />
            <generator class="uuid"/>
        </id>
       
        <property name="... skipped >

      <many-to-one name="parentCartid" class="com.sns.ukrsov.domain.Cartcontainer"
         column="parentCartid" not-null="true"></many-to-one>

</hibernate-mapping>


Corresponding classes defined with interfaces.

Loading is done using the code
Code:
      Session session = getSession();
       CartcontainerIntf cartToReturn = (CartcontainerIntf) session.load(Cartcontainer.class, cartId);
      //Hibernate.initialize(cartToReturn);
      Set<Cartitems> cItems = cartToReturn.getCartitems();
      Iterator iterator = cItems.iterator();
      while(iterator.hasNext()) {
         iterator.next();
      }

      //Hibernate.initialize(cItems);

      session.close();
      return cartToReturn;


And the error/debug log from hib is
Code:
2011-04-15 14:41:54,585 ERROR [org.hibernate.property.BasicPropertyAccessor] - IllegalArgumentException in class: com.sns.ukrsov.domain.Cartitems, setter method of property: parentCartid
2011-04-15 14:41:54,585 ERROR [org.hibernate.property.BasicPropertyAccessor] - expected type: java.lang.String, actual value: com.sns.ukrsov.domain.Cartcontainer_$$_javassist_4
2011-04-15 14:42:00,203 WARN [org.springframework.web.portlet.DispatcherPortlet] - Handler execution resulted in exception - forwarding to resolved error view
org.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of com.sns.ukrsov.domain.Cartitems.parentCartid
   at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:128)


It's starting to drive me crazy... Tried. probably, everything.... Uni-directional is working ok.
Javassist is in place, besides this everything else seems to be working ok - creating new parent item, add some child items, and it is being saved altogether in a single command with all the keys....

Well, I think the hib debug info displays the cause - I just can't understand where to look any further.

Thanks in advance!


Top
 Profile  
 
 Post subject: Re: many-to-one / one-to-many bidirectional - cannot load set
PostPosted: Sat Apr 16, 2011 2:43 pm 
Beginner
Beginner

Joined: Fri Apr 15, 2005 3:30 pm
Posts: 46
Location: Fortaleza, Brazil
I always use the equivalent of <key column="cartid"> instead of <key column="parentCartid"> but the latter could be legal, just thought I'd mention it sticking out to me. Check your class Cartcontainer, its uuid for id is either not a String or you aren't passing a String to it. UUID is typically its own class before UUID.randomUUID().toString() etc.


Top
 Profile  
 
 Post subject: Re: many-to-one / one-to-many bidirectional - cannot load set
PostPosted: Thu Apr 21, 2011 12:30 am 
Newbie

Joined: Fri Apr 15, 2011 10:53 am
Posts: 2
Found it. It was, as usually so obvious.

I've defined property for parent key in a child object as String, while it should be of Parent type...
Thought if it is declared as string in a database - it should be also as a string in a class...

Everything else works and now quite clear...


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