-->
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.  [ 2 posts ] 
Author Message
 Post subject: No result returned with a query, how to solve this prob?
PostPosted: Mon Jan 08, 2007 7:02 am 
Newbie

Joined: Mon Jan 08, 2007 6:53 am
Posts: 2
Hibernate version: 3.x (the version included in JBoss 4.0.4GA)

Used query:SELECT new AnObject(x.id, x.subObject.property, x.description) FROM AnObject x;

This is the code that execute the query:
Code:
String queryString = "SELECT new AnObject(x.id, x.subObject.property, x.description) FROM AnObject x";

Query query = entityManager.createQuery(queryString);
List<AnObject> listResult = (List<AnObject>)query.getResultList();


The problem is that all the rows that have subObject at NULL are not returned.

The behaviour that I would like would be that if "subObject" is null, the value returned for "x.subObject.property" is null.

Is that possible? If yes how? If no, what solution are you suggesting?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 08, 2007 10:44 am 
Newbie

Joined: Mon Jan 08, 2007 6:53 am
Posts: 2
Problem solved.

Solution used:

Code:
SELECT new AnObject(x.id, CASE WHEN mySubObject IS NOT NULL THEN mySubObject.property END, x.description) FROM AnObject x LEFT JOIN x.subObject mySubObject;


But if you have better solution to propose, don't hesitate.


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