-->
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.  [ 12 posts ] 
Author Message
 Post subject: how to avoid generating useless select statement
PostPosted: Wed May 31, 2006 1:06 pm 
Newbie

Joined: Sun May 14, 2006 5:09 pm
Posts: 11
I have a employee table with following columns:
emp_id,emp_name,dept_code
and a department table with following columns:
dept_code, dept_name

the mapping file fot employee is :
<class name="employee" table="dcm_ipc_t_sess_hdr">
<id name="id" column="emp_id" type="int"/>
<property name="name" column="emp_name"/>
<many-to-one name="dept" fetch="select" column="dept_code" class="department" >

...

on the screen I want to display emp_id,emp_name,dept_code without dept_name, I think only employee table need to be retrieved. but when I catch query the retrieveing of department table also generated as a separate select statement.
How can I avoid this.

Thank you


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 31, 2006 1:15 pm 
Regular
Regular

Joined: Thu Sep 22, 2005 1:53 pm
Posts: 88
Location: Rio de Janeiro
change in:

Code:
<many-to-one name="dept" fetch="select" column="dept_code" class="department" >


fetch="select" to fetch="lazy"

good luck

_________________
Don´t forget to rate!


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 31, 2006 2:00 pm 
Beginner
Beginner

Joined: Tue May 02, 2006 10:04 am
Posts: 29
Shouldn't it be fetch="join" or lazy="true"?


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 31, 2006 2:12 pm 
Regular
Regular

Joined: Thu Sep 22, 2005 1:53 pm
Posts: 88
Location: Rio de Janeiro
imchi wrote:
Shouldn't it be fetch="join" or lazy="true"?


Yes lazy="true" sorry about that this actualy is the default.
How is your query?

_________________
Don´t forget to rate!


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 31, 2006 2:18 pm 
Beginner
Beginner

Joined: Tue May 02, 2006 10:04 am
Posts: 29
jbosseur wrote:
imchi wrote:
Shouldn't it be fetch="join" or lazy="true"?


Yes lazy="true" sorry about that this actualy is the default.
How is your query?


Do you mean the one in the other topic? It's working ok, as far as I see.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 31, 2006 2:29 pm 
Regular
Regular

Joined: Thu Sep 22, 2005 1:53 pm
Posts: 88
Location: Rio de Janeiro
Sorry not yours but the one from richwin618 he gets the extra select....
The fetch property has nothing to do with the extra select....

Please post the code for the query.

_________________
Don´t forget to rate!


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 31, 2006 4:08 pm 
Newbie

Joined: Sun May 14, 2006 5:09 pm
Posts: 11
Thanks everyone.

I did changed to fetch ="join". it merged into one single join query.however,what I want is even nojoin becuse in my example,everything I need are emp_id,emp_name,dept_code from employee table, I don't need anything from department table,even I setup relationship in the mapping file.
the generated query is:

Select this_.emp_id As emp1_40_1_, this_.emp_name As emp_n2_40_1_, this_.dept_id As dept3_40_1_, dept2_.dept_id As dept1_24_0_, dept2_.dept_name As dept2_24_0_
From employee this_ Inner Join department dept2_
On this_.dept_id=dept2_.dept_id


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 31, 2006 4:43 pm 
Newbie

Joined: Sun May 14, 2006 5:09 pm
Posts: 11
the code for the query is very simple:
Criteria crit = emp.createCriteria(Employee.class);
result = crit.list();


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 01, 2006 7:47 am 
Regular
Regular

Joined: Thu Sep 22, 2005 1:53 pm
Posts: 88
Location: Rio de Janeiro
I am using Hibernate 3.1

I got it working with the following in the mapping:

Code:
fetch="select" lazy="proxy"


Good Luck

_________________
Don´t forget to rate!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 01, 2006 10:21 am 
Newbie

Joined: Sun May 14, 2006 5:09 pm
Posts: 11
i tried fetch="select" lazy="proxy" like:


<class name="employee" table="dcm_ipc_t_sess_hdr">
<id name="id" column="emp_id" type="int"/>
<property name="name" column="emp_name"/>
<many-to-one name="dept" fetch="select" lazy="proxy" column="dept_code" class="department" >

it's still generate query to the department table

by the way, I'm doing this in a multi-tier web application, in the DAO,I'm doing ceritiria.list(), in the JSP ,I try to get and display each element such as id,name,dept_code.the structure like:JSP->EJB->DAO.

is this happened beacuse inside DAO which access database with Hibernate doesn't know what element will be accessed by JSP,that's why it try to get everything include element from department table? until JSP to get element from list,it's to late to realize it is useless to retrieve department table?

if this is true, then the lazy fetch is useless in a multi-tier application

the fetching is so hard to control


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 01, 2006 8:15 pm 
Newbie

Joined: Sun May 14, 2006 5:09 pm
Posts: 11
I'm so confused about the hibernate fetching


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 02, 2006 9:01 pm 
Newbie

Joined: Sun May 14, 2006 5:09 pm
Posts: 11
??


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