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?