Last active
August 29, 2015 14:26
-
-
Save deigote/549dcecdbb2a6ba80074 to your computer and use it in GitHub Desktop.
Hibernate criteria: Wrong results when join + pagination
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Car { | |
static hasMany = [brands: Brand] | |
} | |
class Brand { } | |
class CarService { | |
def searchCars(int firstResult, int maxResults) { | |
Car.createCriteria().list { | |
createAlias('brands', 'brands', CriteriaSpecification.INNER_JOIN) | |
'in'('id', [1, 2].collect {it.toLong() } ) // Make sure Car(1) and Car(2) have at least 2 brands | |
setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY) | |
setFirstResult(firstResult) | |
setMaxResults(maxResults) | |
} | |
} | |
// This assert fails | |
def proveSearchIsBroken() { | |
assert searchCars(0, 1).first() != searchCars(1, 1).first() | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment