-->
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.  [ 5 posts ] 
Author Message
 Post subject: Broken HQL query
PostPosted: Wed Dec 03, 2003 6:11 pm 
Newbie

Joined: Wed Dec 03, 2003 5:58 pm
Posts: 4
Location: New York City
HQL queries such as:

Code:
select new FooHolder(foo) from Foo as foo...


do not return fully loaded Foo instances. The constructor of FooHolder is invoked with Foo instances that are half-baked (most properties are set to null).

Changing this query to:

Code:
select foo from Foo as foo


returns fully loaded Foo instances.

Any ideas why the first query returns bad data?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 03, 2003 7:38 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Interesting, projection is (usually) used to collect a subset of the object properties. I would assume from what you are saying your only getting the primary key. The SQL would tell the story, anyway, create an entry in JIRA.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 03, 2003 9:01 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
The constructor of FooHolder is invoked with Foo instances that are half-baked (most properties are set to null)


Yes, this is expected. As David says, the use of the select new syntax is for projection.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 03, 2003 10:21 pm 
Newbie

Joined: Wed Dec 03, 2003 5:58 pm
Posts: 4
Location: New York City
In the Hibernate PDF reference manual the following example appears:

Code:
select new Family(mother, mate, offspr)
from eg.DomesticCat as mother
join mother.mate as mate
left join mother.kittens as offspr


As far as I can tell this is almost identical to the example I posted pointing out the potential bug in Hibernate. In both cases, a group of objects is selected in the query and used to construct a non-persistent class instance.

Am I misreading this example from the manual?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 04, 2003 2:43 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
The example is bad.


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