I
Igor
Hi all,
DB: MySQL
Hibernate 2.0.1
I have a very simple (one-to-many) relationship between two tables
QUESTIONS ANSWERS
------------------ ----------------------
id: long id: long
text: string qid: long
text: string
qid is foreign key.
In my Question.hbm.xml I have the following:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD
2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="my.Question" table="questions">
<id column="id" name="id" type="long">
<generator class="identity"/>
</id>
<property column="text" length="200" name="text" not-null="true"
type="string"/>
<set name="answers" table="answers" lazy="false">
<key column="qid"/>
<one-to-many class="my.Answer" />
</set>
</class>
</hibernate-mapping>
There is more than one answer for a question always.
What happens is when I load a question with answers I only get one answer
back, though
in the hibernate trace I see the result set returned more answers and
objects were initialized.
What is wrong?
I tried to use list instead of set with id as index column, but result was
N+1 entry. Additional entry was null.
I still don't understand what should I use as an index column in this case.
Please help.
thanks in advance,
Igor
DB: MySQL
Hibernate 2.0.1
I have a very simple (one-to-many) relationship between two tables
QUESTIONS ANSWERS
------------------ ----------------------
id: long id: long
text: string qid: long
text: string
qid is foreign key.
In my Question.hbm.xml I have the following:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD
2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="my.Question" table="questions">
<id column="id" name="id" type="long">
<generator class="identity"/>
</id>
<property column="text" length="200" name="text" not-null="true"
type="string"/>
<set name="answers" table="answers" lazy="false">
<key column="qid"/>
<one-to-many class="my.Answer" />
</set>
</class>
</hibernate-mapping>
There is more than one answer for a question always.
What happens is when I load a question with answers I only get one answer
back, though
in the hibernate trace I see the result set returned more answers and
objects were initialized.
What is wrong?
I tried to use list instead of set with id as index column, but result was
N+1 entry. Additional entry was null.
I still don't understand what should I use as an index column in this case.
Please help.
thanks in advance,
Igor