-->
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.  [ 4 posts ] 
Author Message
 Post subject: How to 'OR' two criteria created by createCriteria
PostPosted: Mon Jun 04, 2007 3:31 am 
Newbie

Joined: Mon Jun 04, 2007 3:17 am
Posts: 4
Good day.

Someone has post a similar question, but I can't find a working solution so far. Could anyone please have a look , you are forum hero if you can solve it.

Basically I need 'or' two criteria. The scenario is that : we got a TXN, if the TXN is for stock , then TXN.stockLegs will be a non empty collection; if the TXN is for foreign exchange, the TXN.fxLegs will be a non empty collection;

Element in stockLegs is of type StockLeg; Element in fxLegs is FXLeg; both StockLeg and FXLeg got a field called currency.

Now I want to get all TXNs that involve USD, for example.

That is : get all transactions that either its stockLegs contains any stockLeg with USD currency ; or its fxLegs contains any fxLeg with USD currency;

Hibernate Criteria.createCriteria sounds like a solution, but thing is that hibernate will automatically 'and' criteria created . But what I need is really 'OR' .

Any solutions ?

regards


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 04, 2007 6:15 am 
Senior
Senior

Joined: Thu May 17, 2007 2:31 am
Posts: 194
Location: Sri Lanka
Hi


List b = sess.createCriteria(TXN.class,"t")
.createCriteria("stockLegs","sl")
.createCriteria("t.fxLegs","fl")
.add(Restrictions.or(Restrictions.eq("sl.currency", "USD") ,Restrictions.eq("fl.currency", "USD"))).list();

this may similar to your database structure

Amila

(Don't forget to rate if helps)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 04, 2007 7:36 pm 
Newbie

Joined: Mon Jun 04, 2007 3:17 am
Posts: 4
Thanks Amila. I tried this solution and looks like it's not what I am after.

The following code essentially produced sql that 'and' two criteria together, while I really need 'or'.

I tried to use the 'LEFT_JOIN' when calling the criteria.createCriteria. It worked , but the performance just like a dog.

I think the question is to union two result set, that is : txns with stock legs involving USD and txns with fx legs involving USD.

regards

CFN


amila733 wrote:
Hi


List b = sess.createCriteria(TXN.class,"t")
.createCriteria("stockLegs","sl")
.createCriteria("t.fxLegs","fl")
.add(Restrictions.or(Restrictions.eq("sl.currency", "USD") ,Restrictions.eq("fl.currency", "USD"))).list();

this may similar to your database structure

Amila

(Don't forget to rate if helps)


Top
 Profile  
 
 Post subject: Union support
PostPosted: Tue Jun 05, 2007 7:00 pm 
Newbie

Joined: Mon Jun 04, 2007 3:17 am
Posts: 4
I checked the forum and found that 'UNION' is not currently supported by HQL or Hibernate Criteria.

I will just give up and compromise the requirement a bit.


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