I have a database include eventType and event Tables
eventType
- id
- name
event
- id
- name
- location
- eventType_id
- eventSubType_id
where eventType_id and eventTypeSubtype_id reference to eventType Table.
What i want to do with hibernate is select all events that have :
I did :
EventCriteria.createCritria("eventType").add(Expression.in("id"),new Long [] {2L,6L});
EventCriteria.createCriteria("eventSubType").add(Expression.in("id", new Long [] {2L,null}));
The output not consider the events that have eventype with id (2 or 6) and eventSubType is null, it consider only the events that have eventype with id (2 or 6) and eventSubType is (2). The output must Be both
Thanks
Assuming that your eventType numbers are ids...
select event
from Event event
where event.eventType_id in (2,6)
and (eventSubType is null
or eventSubType = 2)
您使用eq
代替in
...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.