-->
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.  [ 3 posts ] 
Author Message
 Post subject: Many to many and many to one doesn't fetch everything
PostPosted: Mon Apr 03, 2006 5:47 am 
Newbie

Joined: Mon Dec 12, 2005 5:21 pm
Posts: 4
Please, help me to solve this problem:
The session.load doesn't load all shifts associated with a schedule. It does load only the first shift associated with the schedule the rest is ignored.


The schedule class has a collection of shifts ,and shift class has a collection of employees and vice versa employee class has a collection of shifts.
Any help would be appreciated, thanks


Hibernate version:
3.1
Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="edu.ttst.dom.Schedule" table="Schedule_ttst">
<id name="id" type="long" column="scheduleId">
<generator class="increment"/>
</id>
<property name="name" insert="true" update="true">
<column name="name"/>
<type name="string"></type>
</property>

<property name="startDate" insert="true" update="true">
<column name="startDate"/>
<type name="edu.ttst.dom.Date"/>
</property>

<property name="endDate" insert="true" update="true">
<column name="endDate"></column>
<type name="edu.ttst.dom.Date"/>
</property>

<bag name="shifts" lazy="false" outer-join="true">
<key column="shiftId"/>
<one-to-many class="edu.ttst.dom.Shift"/>
</bag>
</class>
</hibernate-mapping>

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="edu.ttst.dom.Shift" table="Shift_ttst">
<id name="id" type="long" column="shiftId">
<generator class="increment"/>
</id>
<property name="date" insert="true" update="true">
<column name="date"/>
<type name="edu.ttst.dom.Date"/>
</property>
<property name="startTime" insert="true" update="true">
<column name="startTime"/>
<type name="edu.ttst.dom.Time"/>
</property>
<property name="endTime" insert="true" update="true">
<column name="endTime"/>
<type name="edu.ttst.dom.Time"/>
</property>
<property name="capacity" insert="true" update="true">
<column name="capacity"/>
<type name="int"/>
</property>
<!--<property name="tasks" type="string" column="tasks" insert="true" update="true"/>-->
<many-to-one name="schedule" fetch="join" lazy="false" class="edu.ttst.dom.Schedule" column="scheduleId"/>
<bag name="employees" inverse="true" table="Shift_Employee_Assignment">
<key column="shiftId"/>
<many-to-many column="employeeId"
class="edu.ttst.dom.Employee" outer-join="true"/>
</bag>

</class>
</hibernate-mapping>

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="edu.ttst.dom.Employee" table="Employee_ttst">
<id name="id" type="long" column="employeeId">
<generator class="increment"/>
</id>
<property name="loginId" insert="true" update="true">
<column name="loginId" unique="true" not-null="true"/>
<type name="string"/>
</property>

<property name="firstName" insert="true" update="true" >
<column name="firstName"/>
<type name="string"/>
</property>

<property name="lastName" insert="true" update="true">
<column name="lastName"/>
<type name="string"/>
</property>

<property name="password" insert="true" update="true">
<column name="password"/>
<type name="string"/>
</property>

<property name="privileged" insert="true" update="true" >
<column name="privileged" />
<type name="boolean"/>

</property>

<property name="email" insert="true" update="true">
<column name="email"/>
<type name="string"/>
</property>

<property name="homePhone" insert="true" update="true">
<column name="homePhone"/>
<type name="string"/>
</property>

<property name="cellPhone" insert="true" update="true">
<column name="cellPhone"/>
<type name="string"/>
</property>

<property name="businessPhone" insert="true" update="true">
<column name="businessPhone"/>
<type name="string"/>
</property>
<bag name="shifts" table="Shift_Employee_Assignment">
<key column="employeeId"/>
<many-to-many column="shiftId"
class="edu.ttst.dom.Shift" outer-join="true"/>
</bag>
<!-- inverse end -->


</class>
</hibernate-mapping>



Code between sessionFactory.openSession() and session.close():
Session session = HibernateUtil.currentSession();
schedule=(Schedule) session.load(Schedule.class,id);
session.flush();


Name and version of the database you are using:
Mysql 5


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 03, 2006 6:15 pm 
Newbie

Joined: Mon Dec 12, 2005 5:21 pm
Posts: 4
Any IDEA


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 04, 2006 1:14 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
I'd start by checking out your equals and hashCode methods in the Shift class. Also verify that you have more than one Shift in the DB: it's pretty easy to misuse bags, accidentally having every "add" operation replace the previous contents, instead of adding to them.

I'd also check the formatting of big posts before posting (see the "Preview" button). code tags work a treat.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.