-->
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.  [ 6 posts ] 
Author Message
 Post subject: projection query (select a,b,c instead of all columns)
PostPosted: Mon Nov 28, 2005 7:18 am 
Newbie

Joined: Mon Nov 28, 2005 6:49 am
Posts: 4
Pals,
I am replacing an existing hql query like (simplified version),
"from Person pers" with,
"select new MyPersonRow(pers.lastName, pers.firstName, pers.otherDataObj) from Person pers"

where lastName, firstName are string properties in Person and otherDataObj is a user defined Type OtherData. Person maps to table PERSON and otherDataObj maps to table OTHERDATA which is a many-to-one association inside person.hbm.xml.

I notice that if otherDataObj returns null from database, then no results are returned. If it has a valid value in table, then correct 'person' list is returned. i.e. results are returned only if all properties queried in the projection query have valid return values from table. No result is returned even if one of the queried projection column is null in table.

Is this the expected behavior? Is there a work around where by I will still get 'person' list with otherDataObj property null inside the 'Person' objects?
Thanks,
Bzee


Top
 Profile  
 
 Post subject: any response to projection query returning null?
PostPosted: Tue Nov 29, 2005 1:06 am 
Newbie

Joined: Mon Nov 28, 2005 6:49 am
Posts: 4
Pals,
Is there any solution to the projection query returning null result problem as illustrated below? Or if the query is not intelligible, I will reframe it?
thx.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 29, 2005 1:31 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
using "pers.otherDataObj" as a select expression forces Hibernate to use an inner join...


Top
 Profile  
 
 Post subject: projection query - any work around for the inner join?
PostPosted: Wed Nov 30, 2005 1:23 am 
Newbie

Joined: Mon Nov 28, 2005 6:49 am
Posts: 4
Thanks Steve. I do see that from the results. But is there a work around for same? or possible to reframe the query such that results are returned even if pers.otherDataObj is null? I do want to use the projection query with dynamic instantiation and quite a few tries in modifying the hql failed for me.

My hql currently looks something like,

Code:
select new MyPersonRow(pers.lastName, pers.firstName, pers.otherDataObj) from Person pers;


and I want to indicate that 'return me the results even if otherDataObj is null or empty ?


Top
 Profile  
 
 Post subject: Re: projection query results
PostPosted: Thu Dec 01, 2005 7:45 am 
Newbie

Joined: Mon Nov 28, 2005 6:49 am
Posts: 4
Hi,

I got the problem resolved by asking hibernate to make an outer join as in following hql:

Code:
select new MyPersonRow(pers.lastName, pers.firstName, pers.otherDataObj)
from Person pers
left join fetch pers.otherDataObj


where 'otherDataObj' has its own hbm.xml and table and Java class. In my caes, 'otherDataObj' was having a <many-to-one> association inside Person.hbm.xml.

But I'm still surprised how forcing a eager fetch like above solves the problem while making the original query I posted returns empty results.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 01, 2005 8:10 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
do you understand the difference between an inner and an outer join?


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