Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 47b2bf0

Browse files
committed
#171 Test incorrect result with sub-query due to this_ alias conflict
1 parent 8310312 commit 47b2bf0

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

grails-datastore-gorm-hibernate5/src/test/groovy/grails/gorm/tests/DetachCriteriaSubquerySpec.groovy

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,36 @@ class DetachCriteriaSubquerySpec extends GormDatastoreSpec {
4343
result.size() == 1
4444
}
4545

46+
void "test that detached criteria subquery should create implicit alias instead of using this_"() {
47+
48+
setup:
49+
User supVisor = createUser('[email protected]')
50+
User user1 = createUser('[email protected]')
51+
User user2 = createUser('[email protected]')
52+
53+
Group group1 = createGroup('Group 1', supVisor)
54+
Group group2 = createGroup('Group 2', supVisor)
55+
56+
assignGroup(user1, group1)
57+
assignGroup(user1, group2)
58+
59+
when:
60+
String supervisorEmail = '[email protected]'
61+
DetachedCriteria<User> criteria = User.where {
62+
def u = User
63+
exists(
64+
GroupAssignment.where {
65+
user.id == u.id && group.supervisor.email == supervisorEmail
66+
}.id()
67+
)
68+
}
69+
List<User> result = criteria.list()
70+
71+
then:
72+
noExceptionThrown()
73+
result.size() == 1
74+
}
75+
4676
private User createUser(String email) {
4777
User user = new User()
4878
user.email = email
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
#org.slf4j.simpleLogger.defaultLogLevel=debug
2-
org.slf4j.simpleLogger.log.org.hibernate=trace
2+
#org.slf4j.simpleLogger.log.org.hibernate=trace
3+
#org.slf4j.simpleLogger.log.org.hibernate.SQL=debug

0 commit comments

Comments
 (0)