collection doesn't get all matching entries
by Anja Fischer, IBE
Hi Hibernate users,
since a few days I am puzzling about a problem with a one-to-many
collection mapping.
The collection does just fetch one single element and not all matching
entries.
A 'student' has many 'exams'. There are 2 tables STUDENT and EXAM. They
are connected with the primary key of a student named 'matrinumber'.
I have written a student mapping which contains a set with exams.
Here is the mapping code:
<class name="beans.Student" table="Student" lazy="false">
<id name="matrinumber" type="long"></id>
<property name="sex" column="sex" type="string"/>
<property name="academictitle"
column="academictitle" type="string"/>
<property name="surname" column="surname"
type="string"/>
<property name="firstname" column="firstname"
type="string"/>
<property name="beginnpractyear"
column="beginnpractyear" type="integer"/>
<property name="email" column="email"
type="string"/>
<property name="telephone" column="telephone"
type="string"/>
<property name="mobile" column="mobile"
type="string"/>
<property name="notice" column="notice"
type="text"/>
<one-to-one name="marks" class="beans.Mark"
cascade="all" constrained="true"/>
<set name="exams" lazy="false">
<key column="matrinumber"/>
<one-to-many class="beans.Exam"/>
</set>
</class>
<class name="beans.Exam" table="Exam" lazy="false">
<id name="matrinumber" type="long"></id>
<property name="datum" column="datum" type="calendar"/>
<property name="subject" column="subject" type="string"/>
<property name="participated" column="participated"
type="boolean"/>
<property name="excused" column="excused" type="boolean"/>
<property name="mark" column="mark" type="float"/>
<property name="comment" column="comment" type="string"/>
</class>
The sql code is following:
CREATE TABLE `exam` (
`matrinumber` bigint(20) unsigned NOT NULL,
`datum` date NOT NULL,
`subject` varchar(2) NOT NULL,
`participated` tinyint(1) default NULL,
`excused` tinyint(1) default NULL,
`mark` float unsigned NOT NULL,
`comment` varchar(500) default NULL,
KEY `matrinumber` (`matrinumber`),
CONSTRAINT `exam_ibfk_1` FOREIGN KEY (`matrinumber`) REFERENCES
`student` (`matrinumber`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `student` (
`matrinumber` bigint(20) unsigned NOT NULL,
`sex` varchar(1) default NULL,
`academictitle` varchar(50) default NULL,
`surname` varchar(50) NOT NULL,
`firstname` varchar(30) NOT NULL,
`beginnpractyear` int(11) NOT NULL,
`email` varchar(60) NOT NULL,
`telephone` varchar(20) default NULL,
`mobile` varchar(20) default NULL,
`notice` text,
PRIMARY KEY (`matrinumber`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
How already written above, I always get just one single element in the
collection exams. But in the database are 6 exam entries.
I have no more ideas concerning this. Perhaps there is someone out who
can give me some hints or debugging ideas.
Thanks all.
Anja
17 years, 5 months