Skip to content

Commit 3c161e0

Browse files
gavinkingsebersole
authored andcommitted
test for JPQL 'this' implicit identification variable
Signed-off-by: Gavin King <[email protected]>
1 parent 3c4a340 commit 3c161e0

File tree

1 file changed

+36
-0
lines changed
  • hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/thisalias

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package org.hibernate.orm.test.query.hql.thisalias;
2+
3+
import jakarta.persistence.Basic;
4+
import jakarta.persistence.Entity;
5+
import jakarta.persistence.GeneratedValue;
6+
import jakarta.persistence.Id;
7+
import org.hibernate.testing.orm.junit.DomainModel;
8+
import org.hibernate.testing.orm.junit.SessionFactory;
9+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
10+
import org.junit.jupiter.api.Test;
11+
12+
@SessionFactory
13+
@DomainModel(annotatedClasses = HQLThisTest.This.class)
14+
public class HQLThisTest {
15+
@Test
16+
void test(SessionFactoryScope scope) {
17+
scope.inTransaction(s -> s.persist(new This("gavin")));
18+
scope.inSession(s -> {
19+
s.createSelectionQuery("select this.name from This this where this.name = 'gavin'").getSingleResult();
20+
s.createSelectionQuery("from This where this.name = 'gavin'").getSingleResult();
21+
s.createSelectionQuery("select this.name from This order by this.name").getSingleResult();
22+
s.createSelectionQuery("select count(this) from This").getSingleResult();
23+
s.createSelectionQuery("select id(this) from This").getSingleResult();
24+
});
25+
}
26+
@Entity
27+
static class This {
28+
@Id @GeneratedValue
29+
long id;
30+
@Basic(optional = false)
31+
String name;
32+
33+
This(String gavin) {}
34+
This() {}
35+
}
36+
}

0 commit comments

Comments
 (0)