-->
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: Hibernate FetchMode SELECT issue
PostPosted: Tue Feb 19, 2013 1:13 am 
Newbie

Joined: Tue Feb 19, 2013 1:01 am
Posts: 1
I'm trying to perform a simple One to Many association with Fetch Mode SELECT. In my case, there is an EMPLOYEE table that has been mapped to EMPLOYEE_EXPENSE with One to Many association.

Here is the snippet
Employee Class
@Fetch(FetchMode.SELECT)
@OneToMany(mappedBy="employee", fetch=FetchType.LAZY)
private Set<EmployeeExpense> employeeExpenses;

Employee Expense Class
@Id
@ManyToOne
@JoinColumn(name="EMP_ID")
private Employee employee;


Im doing this below code to fetch and display the values
tx = session.beginTransaction();
emp = (Employee) session.get(Employee.class, empId);

log.info("Employee Expense size=" + emp.getEmployeeExpenses().size());
for (EmployeeExpense ee: emp.getEmployeeExpenses()) {
log.info("expense claim=" + ee.getExpenseClaim());
}
session.getTransaction().commit();

For the empId = 7369, i see many records in EmployeeExpense table. But what gets printed from the above statements is just one record..
[main] [class: EmployeeDAOImpl] INFO - Employee Expense size=1
[main] [class: EmployeeDAOImpl] INFO - expense claim=3072.43

I see hibernate is executing one SELECT statement to fetch the Employee 7369 and then its making another SELECT statement to fetch the associated EMPLOYEE EXPENSE records. Eventhough there are many EMPLOYEE EXPENSE records in the database for the EMPID 7369, what gets fetched is JUST ONE EmployeeExpense..

Whats happening here? Could anyone help me out? Thanks!


Top
 Profile  
 
 Post subject: Re: Hibernate FetchMode SELECT issue
PostPosted: Tue Feb 19, 2013 1:28 pm 
Newbie

Joined: Sat May 19, 2012 7:42 am
Posts: 4
What are EmployeeExpense's ids ? How do you declare its ?


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.