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
|