| Author |
AND/OR in Hibernate - Criteria object
|
Somak Dalui
Ranch Hand
Joined: Apr 19, 2005
Posts: 35
|
|
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.
|
 |
Halcon Guatemala
Ranch Hand
Joined: Sep 06, 2006
Posts: 57
|
|
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: 35
|
|
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
|
|
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... I hope this helps
|
 |
Somak Dalui
Ranch Hand
Joined: Apr 19, 2005
Posts: 35
|
|
|
Thanks a ton Halcon, been searching for the solution for a long time.
|
 |
Somak Dalui
Ranch Hand
Joined: Apr 19, 2005
Posts: 35
|
|
|
Just find out that this is possible by creating alias.
|
 |
John Bartlett
Ranch Hand
Joined: Jan 25, 2006
Posts: 116
|
|
Hi, 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: 35
|
|
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 This gives me a fine SQL.
|
 |
 |
|
|
subject: AND/OR in Hibernate - Criteria object
|
|
|