-->
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.  [ 3 posts ] 
Author Message
 Post subject: Select new User(...)
PostPosted: Tue May 08, 2007 2:39 pm 
Beginner
Beginner

Joined: Wed Jun 14, 2006 9:44 am
Posts: 22
Hibernate version:2.1.7
Name and version of the database you are using: Oracle9i

Hi all,

I need to return a list of objects User, but only some
attributes of an object.

So, I did the following HQL:

Code:
select new User(u.name, u.jobFunction)
from User u


I´ve created the constructor for User:

Code:
// constructor 1
public User()
{
    super();
}

// constructor 2
public User (String userName, String userJobFunction)
{
    this.name = userName;
    this.jobFunction = userJobFunction
}


but this HQL generate many queries and, after all the hibernate
uses the constructor 2.
I don´t need the other data, only the constructor.

How can I do to do not generate many queries in this case?

thanks!!!!


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 08, 2007 5:07 pm 
Newbie

Joined: Thu Jan 04, 2007 1:36 pm
Posts: 16
Have you created that User as just a value object or is it a domain object (including hbm)? If its a domain object, then you'd need to take a look at it to see what it has and also since User is mapped, when you execute the hql, it loads up all the "users" from this table, thereby issuing multiple queries.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 09, 2007 3:33 pm 
Beginner
Beginner

Joined: Wed Jun 14, 2006 9:44 am
Posts: 22
Hi,

I did other test, and the hql is generation with fetch. This is a cause
to generate others queries.
So, if the select clause of hql has a constructor, do not use the fetch
on the from clause to do not generate many queries.

thank you very much!!!!


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