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.  [ 4 posts ] 
Author Message
 Post subject: one-to-many selects but doesn't assign?
PostPosted: Mon Feb 25, 2008 9:10 pm 
Newbie

Joined: Mon Feb 25, 2008 7:18 pm
Posts: 3
Hello,

Ran out of ideas what may be wrong, please help.

Hibernate 3, one-to-many relation: I can see in the log that hibernate selects children (and the query returns what expected) but the Collection property in the parent object is still empty. Would appreciate any hints as it has been a few days and I just have no single idea left. Here's the mapping XML:

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

   <class name="Parent" table="PARENT">
      <id name="id" column="PARENT_REF_NUM" />
      <set name="children" inverse="true">
          <key column="PARENT_REF_NUM"/>
          <one-to-many class="Child" />
      </set>
   </class>

   <class name="Child" table="CHILD">
      <composite-id>
          <key-many-to-one name="parent" class="Parent" column="PARENT_REF_NUM"/>
          <key-property name="seqNum" column="SEQ_NUM"/>
      </composite-id>
      <property name="childName" column="CHLD_NME"/>
    </class>   

</hibernate-mapping>




The code:

Parent parent = hbSession.load(Parent.class, "parent0");
System.out.println(parent.getId()+","+parent.getChildren().size());

prints "parent0, 0"

but the query that hibernate generated to select children, if executed in an SQL tool actually returns the whole bunch of children..

please help,

Max.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 03, 2008 1:25 am 
Newbie

Joined: Mon Feb 25, 2008 7:18 pm
Posts: 3
No single reply in a week.. is it such silly question not worth replying or so complicated that nobody knows the answer?


Top
 Profile  
 
 Post subject: Re: one-to-many selects but doesn't assign?
PostPosted: Mon Mar 03, 2008 4:21 am 
Regular
Regular

Joined: Mon Aug 06, 2007 10:49 am
Posts: 67
Location: Banska Bystrica, Slovakia
ivioix wrote:
Hello,

Ran out of ideas what may be wrong, please help.

Hibernate 3, one-to-many relation: I can see in the log that hibernate selects children (and the query returns what expected) but the Collection property in the parent object is still empty. Would appreciate any hints as it has been a few days and I just have no single idea left. Here's the mapping XML:

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

   <class name="Parent" table="PARENT">
      <id name="id" column="PARENT_REF_NUM" />
      <set name="children" inverse="true">
          <key column="PARENT_REF_NUM"/>
          <one-to-many class="Child" />
      </set>
   </class>

   <class name="Child" table="CHILD">
      <composite-id>
          <key-many-to-one name="parent" class="Parent" column="PARENT_REF_NUM"/>
          <key-property name="seqNum" column="SEQ_NUM"/>
      </composite-id>
      <property name="childName" column="CHLD_NME"/>
    </class>   

</hibernate-mapping>




The code:

Parent parent = hbSession.load(Parent.class, "parent0");
System.out.println(parent.getId()+","+parent.getChildren().size());

prints "parent0, 0"

but the query that hibernate generated to select children, if executed in an SQL tool actually returns the whole bunch of children..

please help,

Max.


just quessing but what about such wrong java code?

public void setChildren(Set children) {
children = children;
}

should be: this.children = children;


Top
 Profile  
 
 Post subject: Re: one-to-many selects but doesn't assign?
PostPosted: Mon Mar 03, 2008 10:12 pm 
Newbie

Joined: Mon Feb 25, 2008 7:18 pm
Posts: 3
ferozz wrote:

just quessing but what about such wrong java code?

public void setChildren(Set children) {
children = children;
}

should be: this.children = children;


Thanks for your reply, ferozz! :)

But no, it's not that. The getter/setter was correctly generated by IDE


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