-->
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: Queries returns nonempty lists?
PostPosted: Tue Jun 21, 2005 1:51 am 
Beginner
Beginner

Joined: Tue Jun 21, 2005 1:36 am
Posts: 29
Location: Houston, TX
Version: Hibernate 3.0

I would appreciate any advice on the following code. This query returns a list with one element that is null if there are no payments for the specifed shipment. Notice that I need to check to see if the size is 1 and if the value is null and remove it so the for loop will not be entered. Is there a way to get the query to return an empty list if no payments are found?

Code:
                List<Payment> payments = hsess.createQuery("select payment from Shipment as s left join s.payments as payment where s.id=:id order by payment.id")
                                              .setInteger("id", shipment.getId())
                                              .list();
                if (payments.size() == 1 && payments.get(0) == null) payments.remove(0);
                for (Payment payment : payments) {
                  // arbitrary payment manipulation
                }

_________________
Thank you for your time,

Jason Long
CEO and Chief Software Engineer
BS Physics, MS Chemical Engineering
http://www.supernovasoftware.com
HJBUG Founder and President
http://www.hjbug.com


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 21, 2005 2:10 am 
Beginner
Beginner

Joined: Tue Jun 21, 2005 1:36 am
Posts: 29
Location: Houston, TX
I apologize for this post. I simply used an inner join and the query behaved as expected.

_________________
Thank you for your time,

Jason Long
CEO and Chief Software Engineer
BS Physics, MS Chemical Engineering
http://www.supernovasoftware.com
HJBUG Founder and President
http://www.hjbug.com


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.