开发者

queries with hibernate

开发者 https://www.devze.com 2022-12-17 13:50 出处:网络
I have a database include eventType and event Tables eventType - id - name event - id - name - location - eventType_id

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 :

  • eventType in (2,6)
  • and eventSubType in (2,null)

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)


You used eq instead of in...

0

精彩评论

暂无评论...
验证码 换一张
取 消