Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 2.17
Mapping documents:
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
Name and version of the database you are using:
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
I have a class
public class TimeAttendance implements Serializable {
private Long timeAttendanceId;
private Employee employee;
private ApprovalStatus approvalStatus;
private Date startTime;
private Date endTime;
...
}
Employee and ApprovalStatus are also classes implementing Serializable.
I want to retrieve TimeAttendance(s) for a particular employee.
public List getTimeAttendances( Long employeeId ) {
List timeAttendances = new ArrayList();
// hibernate query
String hQuery = "from TimeSheet ts " +
"where ts.employee.employeeId = :eid ";
try {
Session session = HibernateHelper.getSession();
Query query = session.createQuery( hQuery );
query.setLong( "eid", employeeId.longValue() );
timeAttendances = query.list();
} catch (InfrastructureException ie) {
System.out.println("TimeAttendanceDAOHibernate.java: ie.getMessage()= " + ie.getMessage());
return timeSheets;
} catch (HibernateException he) {
System.out.println("TimeAttendanceDAOHibernate.java: he.getMessage()= " + he.getMessage());
return timeSheets;
}
return timeSheets;
}
after calling this function as "getTimeAttendances( new Long("77") )",
i expect Hibernate to execute 1 SELECT statement:
select * from time_attendance where employee_id = 77
Hibernate does it but then it start executing select statement for each of the member of the TimeAttendance class which in itself is a class. this is very inefficient as for TimeAttendance class, 8 of its members are also classes.
is there any way to control it? thanks