-->
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: collection initialization problem
PostPosted: Mon May 31, 2004 1:09 pm 
Newbie

Joined: Mon May 31, 2004 12:44 pm
Posts: 1
Hi everybody,

I use Hibernate 2.1.2 and have a little beginner's problem.
In my class Election are three Sets of one-to-many relationships (Voters, Authorities and Choices). When I try to retrieve the complete election data from the database (MySQL 3.2.3) there is just one object in each Set. Hibernate retrieves just one row per Set.

Here is my Java coding:
Code:
String query = "from de.fhn.election.datatypes.Election";
List list = sess.find(query);
elections = new Election[list.size()];
for (int i = 0; i < list.size(); i++) {
  elections[i] = (Election) list.get(i);
}


Here is the mapping file:

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
   <class name="de.fhn.election.datatypes.Election" table="Election"
      dynamic-update="false" dynamic-insert="false" >
      <id name="id" column="id" type="java.lang.Long" >
         <generator class="native">
         </generator>
      </id>
      <property name="subject" type="java.lang.String" update="true"
         insert="true" column="subject" length="60" not-null="true" />
      <many-to-one name="type" class="de.fhn.election.datatypes.ElectionType"
         cascade="none" outer-join="auto" update="true" insert="true"
         column="type_id" />
      <property name="begin" type="java.util.Date" update="true"
         insert="true" column="begin" not-null="true" />
      <property name="end" type="java.util.Date" update="true" insert="true"
         column="end" not-null="true" />
      <property name="result" type="java.math.BigInteger" update="true"
         insert="true" column="result" />
      <property name="p" type="de.fhn.election.datatypes.BigIntegerUserType"
         update="true" insert="true" column="p" not-null="true" />
      <property name="q" type="de.fhn.election.datatypes.BigIntegerUserType"
         update="true" insert="true" column="q" not-null="true" />
      <property name="g" type="de.fhn.election.datatypes.BigIntegerUserType"
         update="true" insert="true" column="g" not-null="true" />
      <property name="h" type="de.fhn.election.datatypes.BigIntegerUserType"
         update="true" insert="true" column="h" not-null="true" />
      <property name="t" type="de.fhn.election.datatypes.BigIntegerUserType"
         update="true" insert="true" column="t" not-null="true" />
      <set name="choices" lazy="false" inverse="true" cascade="all"
         sort="unsorted" >
         <key column="election_id" />
         <one-to-many class="de.fhn.election.datatypes.Choice" />
      </set>
      <set name="voters" lazy="false" inverse="true" cascade="all"
         sort="unsorted" >
         <key column="election_id" />
         <one-to-many class="de.fhn.election.datatypes.Voter" />
      </set>
      <set name="authorities" lazy="false" inverse="true" cascade="all"
         sort="unsorted" >
         <key column="election_id" />
         <one-to-many class="de.fhn.election.datatypes.Authority" />
      </set>
      <!--
            To add non XDoclet property mappings, create a file named
                hibernate-properties-Election.xml
            containing the additional properties and place it in your merge dir.
        -->
   </class>
</hibernate-mapping>


I went through the reference document and tried a few other queries...but no success. The debug message was every time: "1 collections were found in result set". What's wrong? Why is there just one row?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 01, 2004 4:15 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Because in you DB there is 1 child with the election id?

Check the equals/ahshCode impementation too (search the forum)

_________________
Emmanuel


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.