test for JPQL 'this' implicit identification variable

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-05-13 11:39:17 +02:00 committed by Steve Ebersole
parent 3c4a340c5e
commit 3c161e0c82
1 changed files with 36 additions and 0 deletions

View File

@ -0,0 +1,36 @@
package org.hibernate.orm.test.query.hql.thisalias;
import jakarta.persistence.Basic;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
@SessionFactory
@DomainModel(annotatedClasses = HQLThisTest.This.class)
public class HQLThisTest {
@Test
void test(SessionFactoryScope scope) {
scope.inTransaction(s -> s.persist(new This("gavin")));
scope.inSession(s -> {
s.createSelectionQuery("select this.name from This this where this.name = 'gavin'").getSingleResult();
s.createSelectionQuery("from This where this.name = 'gavin'").getSingleResult();
s.createSelectionQuery("select this.name from This order by this.name").getSingleResult();
s.createSelectionQuery("select count(this) from This").getSingleResult();
s.createSelectionQuery("select id(this) from This").getSingleResult();
});
}
@Entity
static class This {
@Id @GeneratedValue
long id;
@Basic(optional = false)
String name;
This(String gavin) {}
This() {}
}
}