This is the query i'm running:
List<Coupon> coupons = getDb().createCriteria(Coupon.class)
.add(Restrictions.le("validFrom", startTime.getTime()))
.add(Restrictions.ge("validUntil", startTime.getTime()))
.add(Restrictions.eq("user", user))
.createAlias("spots", "spotsAlias")
.add(Restrictions.or(
Restrictions.eq("isGlobal", true),
Restrictions.eq("spotsAlias.id", spot.getId())
))
.add(Restrictions.eq("isRedeemed", false))
.add(Restrictions.eq("isDeleted", false))
.add(Restrictions.eq("isActive", true))
.addOrder(Order.asc("isGlobal"))
.addOrder(Order.desc("validFrom"))
.list();
it's supposed to get all coupons that are:
- valid at startTime
- related to user
- global or related to a specific spot
- not redeemed
- not deleted
- activated
the coupons are in many-to-many relationship with spots. the relationship works - this query does return coupons that are specifically related to the queried spot. Unfortunately, it never returns global coupons, even when there are no "local" coupons in the database at all.
Any suggestions? help will be very much appreciated!