I need to write a hibernate criteria for this SQL:
select distinct USER_ID from USER_ROLE
where USER_TERM_DT is null
and ((ROLE_ID in (101,102)
and STATE_ID in ('MD')) or ROLE_ID = 150)
The role_ids will have a combination of values (101,102,150,151)
The OR part only needs to be there if the Role_Id is 150 or 151.
The USER_ROLE table has Role_id & state_id. Only roles 101 & 102 are associated with state_ids.
If all the 4 role_id values are there, the SQL would be like:
select distinct USER_ID from USER_ROLE
where USER_TERM_DT is null
and ((ROLE_ID in (101,102)
and STATE_ID in ('MD')) or ROLE_ID in (150,151))
Please help in this matter. I’m reading I need to use conjunction & disjunction together, but just not able to come up with the right code. Hope it’s clear & my SQL is right.
Something like this should work – replace the ‘is null’ and the ‘in’ expressions with the corresponding Restrictions