Hi to all,
I've this JPA query (please, forget about the fact that the two conditions in 'or' are the same, it's only for example purpose, for having a complex query.):
CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<T> criteria = builder.createQuery(type); Root<RealEstate> realRoot = criteria.from(RealEstate.class); Predicate networkPredicate = builder.and(userGroupJoin.get("groupId").in(groupFriendshipList), builder.equal(realRoot.get("agencyId"), userRoot.get("userId"))); Predicate mlsPredicate = builder.and(userGroupJoin.get("groupId").in(groupFriendshipList), builder.equal(realRoot.get("agencyId"), userRoot.get("userId"))); Predicate conjunctionPredicate = builder.or(networkPredicate, mlsPredicate); criteria.multiselect(realRoot); criteria.where(conjunctionPredicate);
I'm expecting that this will be translated into the following HQL query:
SELECT RealEstate FROM RealEstate INNER JOIN (other tables) WHERE (GroupID IN (48,53) AND RealEstate.AgencyID = User.UserID) OR (GroupID IN (48,53) AND RealEstate.AgencyID = User.UserID)
(note the parenthesys in the or clause)
But this is the actual translation:
select RealEstate from RealEstate inner join other tables... where (GroupID in (48 , 53)) and realestate0_.AgencyID=user1_.UserID or (GroupID in (48 , 53)) and realestate0_.AgencyID=user1_.UserID
The logical order of the actual HQL translation isn't right...in this way the two 'and' statements aren't executed before the 'or' operator, like it should be...where am I wrong? Maybe it's a bug of Hibernate implementation?
Many Thanks,
Antlia