public class Entity {
private boolean suspended;
private String code;
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
@DateTimeFormat(style = "S-")
private DateTime validFrom;
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
@DateTimeFormat(style = "S-")
private DateTime validTill;
}
クエリの意味:「指定された時間の有効性においてコードは一意ですか?」
このクエリを書き直す方法:
select count(o) from Entity o
where o <> :this and o.code = :code and (
(o.validFrom between :validFrom and :validTill and not o.suspended) or
(o.validTill between :validFrom and :validTill and not o.suspended) or
(:validFrom between o.validFrom and o.validTill and not o.suspended)
)