AND/OR in Hibernate - Criteria object

I have a query like "select this_.appNum as y0_ from CoreApplication this_ inner join LoanAndDeposit loananddep2_ on this_.appNum=loananddep2_.CoreApplication_appNum inner join OptionTrade optiontrad1_ on this_.appNum=optiontrad1_.CoreApplication_appNum where this_.applicationType in ( ?, ?, ?, ? ) and this_.status in ( ?, ?, ? ) and optiontrad1_.lastModifiedUser=? and loananddep2_.status=? ". For the last part i.e. OptionTrade.lastModifiedUser and LoanAndDeposit.status I have to do an OR and not an AND. These are generated by sub-Criteria objects are here's the code :

I have an idea that this is done by Conjunction object but can anyone please tell me how in this case ?? Thanks in advance.

Hi Somak, I suggest You use Restrictions instead Expression. You must remember Expression supports nested Expression(s):

Expression.or(Expression1, Expression2);

I hope it helps

"La verdadera sabidur�a viene del temor de Dios"

Somak Dalui
Ranch Hand

Joined: Apr 19, 2005
Posts: 41

posted Feb 16, 2007 23:57:00

0

Hi Halcon, thanks for the reply - I want to create an OR between

and

Can you tell me how can I acheive that ? I want an OR between these two sub-Criteria-s.

Halcon Guatemala
Ranch Hand

Joined: Sep 06, 2006
Posts: 57

posted Feb 19, 2007 10:56:00

0

Hi again Somak, sorry but I didn't know about your 2 criterias You want to do "or" between. It seems any case of sql "union" clause, You know it isn't supported by Criteria API, You might considerate to use SQLQuery for it...

Just curious whether Restrictions.disjunction(); would help you in any way?

e.g.

This is the Restriction version of OR (conjunction is obviously the AND equivelent)

Would this work for you?

John

Somak Dalui
Ranch Hand

Joined: Apr 19, 2005
Posts: 41

posted Mar 02, 2007 23:14:00

0

Yes John this will work, but I have to create an alias before I can refer the properties.Because the properties that I am referring to belongs to the mapped class and not to the parent class.So I am doing