Runtime sleep mode

I have two tables linked together using a one-to-many relationship: employee → department: and a relationship through department_id in the employee table.

I use hibernate: and my hibernation mapping files:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
                                   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- 
    Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping default-lazy="false">
 <class catalog="moi"
  name="com.ebla.moi.correspondence.model.entity.user.User" table="user">
  <id name="id" type="java.lang.Long">
   <column name="id"/>
   <generator class="identity"/>
  </id>
  <many-to-one
   class="com.ebla.moi.correspondence.model.entity.department.Department"
   fetch="select" name="department">
   <column name="department_id"/>
  </many-to-one>
  <property generated="never" lazy="false" name="name" type="java.lang.String">
   <column length="128" name="name" not-null="true"/>
  </property>
  <property generated="never" lazy="false" name="email" type="java.lang.String">
   <column length="128" name="email" not-null="true" unique="true"/>
  </property>
  <property generated="never" lazy="false" name="maritalStatus" type="java.lang.Short">
   <column name="marital_status" not-null="true"/>
  </property>
  <property generated="never" lazy="false" name="hireDate" type="java.lang.String">
   <column length="64" name="hire_date"/>
  </property>
 </class>
</hibernate-mapping>

and the second mapping file:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
                                   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- 
    Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping default-lazy="false">
 <class catalog="moi"
  name="com.ebla.moi.correspondence.model.entity.department.Department" table="department">
  <id name="id" type="java.lang.Long">
   <column name="id"/>
   <generator class="identity"/>
  </id>
  <property generated="never" lazy="false" name="name" type="java.lang.String">
   <column length="256" name="name" unique="true"/>
  </property>
  <set inverse="true" name="users" sort="unsorted">
   <key>
    <column name="department_id"/>
   </key>
   <one-to-many class="com.ebla.moi.correspondence.model.entity.user.User"/>
  </set>
 </class>
</hibernate-mapping>

My problem: sometimes I need to get an employee with his department, and sometimes I only need information about employees without department information ..... and the same thing with a department with an employee .... using the mapping file over sleeping bring the department and its users if I need an employee or not ... how to determine my needs in sleep mode, to get only what I need ...

Thank you

+5
4

"" , :

  • ( "" ). . " e Employee e where..."

  • , " ", Hibernate "". . " e Employee left join fetch e.department, ..."

LLP, Andrea

+10

ICriteria .

SetFetchMode ICriteria, , :

, :

ICriteria crit = theSession.CreateCriteria (typeof(Employee));
crit.SetFetchMode ("Department", FetchMode.Lazy)

.

ICriteria crit = theSession.CreateCriteria (typeof(Employee));
crit.SetFetchMode ("Department", FetchMode.Join)

, fetchmode ( , ), . ( , ).

+8

- , :

  • Employee, ;
  • EmployeeSummary, .

Employee, Employee department.

, , Employee, , EmployeeSummary.

ORM -, , AbstractEmployee, .

+2

All Articles