-->
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: Multiple Mappings
PostPosted: Tue Sep 20, 2005 3:35 pm 
Newbie

Joined: Tue Sep 20, 2005 3:11 pm
Posts: 1
I'm baffled by this...
I have a class Student. Student has a set, FirstChoices, a set, SecondChoices, and a set, Courses.
All three of these sets are of type Course.

I also have tables Student, Student_FirstChoices, Student_SecondChoices, and Course_Student.

For the *most* part, this goes fairly smoothly; however, when I do an inclusion check to see if the student has a firstchoice that matches the current course (so that I can highlight it) [if(student.getFirstChoices().contains(course))], hibernate appears to be getting mixed up and returning true for courses that are not in the firstchoices set, but *are* in the second choices set.

The debugger shows the course in secondchoices *and* in firstchoices but a select statement in the actual DB shows that the course is in secondchoices exclusively.

A buddy of mine at the office said that it has to do with the fact that I've got the same class referenced three different ways in the hbm file. I don't know if he's correct, but it doesn't seem right. There's nothing out of the ordinary with regards to a sql statement or out-of-bounds with regards to a DB.

Any ideas what could be causing secondchoices to leak into firstchoices? It doesn't seem to leak the other direction, nor does it appear to leak into courses

---snip from Student.hbm.xml--
<pre>
<set name="courses" table="Course_Student" lazy="true">
<key column="student_id"/>
<many-to-many column="course_id" class="org.voight.ats.dto.Course"/>
</set>

<set name="firstChoices" table="Student_Firstchoices" lazy="true">
<key column="student_id"/>
<many-to-many column="course_id" class="org.voight.ats.dto.Course"/>
</set>
<set name="secondChoices" table="Student_Secondchoices" lazy="true">
<key column="student_id"/>
<many-to-many column="course_id" class="org.voight.ats.dto.Course"/>
</set>
</pre>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 20, 2005 7:08 pm 
Regular
Regular

Joined: Mon Aug 22, 2005 1:11 pm
Posts: 50
Location: Pasadena, CA
I have had a similar problem recently when I wanted to multiple sets of the same objects. The problem is that hibernate cannot differentate between objects of which type go in which set.

There two possible solutions to this:

1. add a property to course that tells what type it is

2. extned course into the diffrent types you want and put the type into your mappings

ie:

* @hibernate.discriminator
* column="type"

this way you can still have your two collections but there is away to tell them apart.


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.