-->
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.  [ 11 posts ] 
Author Message
 Post subject: Criteria and too many columns in final Select
PostPosted: Wed Oct 11, 2006 6:11 am 
Newbie

Joined: Wed Oct 11, 2006 5:20 am
Posts: 8
Hi,

I noticed that using Criteria API I received always too many columns in final Select.

e.g.:

Code:
Class A {
  int id;
  String name;
  List bs;
...
}

Class B {
  int id;
  String name;
  A a;
...
}

code snippet:
Code:
...
Criteria criteria = session.createCriteria(A.class).createCriteria("bs")
   .add(Property.forName("name").eq("example"));

List A = session.list();
...

Select looks like this:
Code:
select this_.id as id0_1_,
       this_.name as name0_1_,
       this_.b_id as b5_0_1_,
       b1_.id as id2_0_,
       b1_.name as name2_0_
from A this_
     inner join B b1_ on this_.b_id = b1_.id
where b1_.id = ?


I'd like to ask you if there is method to limit columns amount in final select to ones from entity A?

I found discusion about this issue, but there are only some workarounds:
http://forum.hibernate.org/viewtopic.ph ... torder=asc

Slawek


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 12, 2006 2:15 am 
Newbie

Joined: Wed Oct 11, 2006 5:20 am
Posts: 8
I've asked this question because i'm going to create Improvement Issue in Hibernate JIRA if there is no direct solution.

Described problem is the biger the more columns has each joined entity. It can kill an efficiency.

Slawek


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 12, 2006 3:45 am 
Newbie

Joined: Tue Aug 15, 2006 5:49 am
Posts: 4
I would prefer a switch on every createCriteria(). If you send "true" all eager fields will be fetched, and if you send "false" nothing will be fetched or maybe only the primary key.

What do you think?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 12, 2006 4:03 am 
Newbie

Joined: Wed Oct 11, 2006 5:20 am
Posts: 8
muhviehstarr wrote:
I would prefer a switch on every createCriteria(). If you send "true" all eager fields will be fetched, and if you send "false" nothing will be fetched or maybe only the primary key.

What do you think?


I like your idea :)

If somebody has something to add before I create JIRA issue, please write it down hiere.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 12, 2006 4:04 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
as described at the forum you put a link to...you want to use the Projections api

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 12, 2006 5:54 am 
Newbie

Joined: Wed Oct 11, 2006 5:20 am
Posts: 8
max wrote:
as described at the forum you put a link to...you want to use the Projections api


This is the solution described in http://forum.hibernate.org/viewtopic.ph ... projection
In the last post kiransg claims that the object received this way is not fully-fledged (if I can write like this) hibernate object.

Quote:
Moreover, the Teacher object got by the above method will not have the proxy objects for the other relations.
ie, the teacher.getDepartment() or teacher.getCourses() will not give the objects.


If so, this is big disadventage and it's not what I'm thinking about.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 12, 2006 9:18 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
of course it is not full fledged since you only want parts of the ojbect!?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 12, 2006 9:46 am 
Newbie

Joined: Wed Oct 11, 2006 5:20 am
Posts: 8
You are absolutely right taking into consideration example with fiew only properties of some entity.

I'm trying to describe slightly different situation. I want to receive a list of complete objects (hibernate entity objects) but without additional columns of joined table in sql generated by hibernate.
My example shown in the first post of this discussion is good one I hope.

Functionally, sql code generated by Criteria is OK, but there is too much data read from DB, thus it seems not to be as efficient as it could be.

Do I have right point of view? I'm quite new in Hibernate, so I can fallow bad track with ease.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 13, 2006 8:34 am 
Newbie

Joined: Wed Oct 11, 2006 5:20 am
Posts: 8
I'd like to take an opinion from you Max.
Are you prone to my proposition?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 17, 2006 3:14 am 
Newbie

Joined: Wed Oct 11, 2006 5:20 am
Posts: 8
A decided to create Hibernate JIRA Improvement issue.
http://opensource.atlassian.com/project ... e/HHH-2150


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 17, 2006 3:17 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
and i decided to close it since it is not a bug nor in any way a improvement request that isn't fullfilled by alot of the current options.

_________________
Max
Don't forget to rate


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