HHH-18649 test
This commit is contained in:
parent
efc50aad00
commit
ad33eb4f64
|
@ -21,7 +21,6 @@ import org.hibernate.orm.test.jpa.metamodel.Customer_;
|
||||||
import org.hibernate.orm.test.jpa.metamodel.Order;
|
import org.hibernate.orm.test.jpa.metamodel.Order;
|
||||||
import org.hibernate.orm.test.jpa.metamodel.Order_;
|
import org.hibernate.orm.test.jpa.metamodel.Order_;
|
||||||
import org.hibernate.testing.orm.junit.JiraKey;
|
import org.hibernate.testing.orm.junit.JiraKey;
|
||||||
import org.hibernate.testing.orm.junit.JiraKey;
|
|
||||||
import org.hibernate.testing.orm.junit.SkipForDialect;
|
import org.hibernate.testing.orm.junit.SkipForDialect;
|
||||||
|
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
/*
|
||||||
|
* SPDX-License-Identifier: LGPL-2.1-or-later
|
||||||
|
* Copyright Red Hat Inc. and Hibernate Authors
|
||||||
|
*/
|
||||||
|
package org.hibernate.orm.test.jpa.metadata;
|
||||||
|
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.NamedEntityGraph;
|
||||||
|
import jakarta.persistence.NamedQuery;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@NamedQuery(name = "TextById",
|
||||||
|
query = "select text from Record where id = ?1")
|
||||||
|
@NamedQuery(name = "AllRecords",
|
||||||
|
query = "from Record order by timestamp, id")
|
||||||
|
@NamedQuery(name = "AllRecordsAsTuples",
|
||||||
|
query = "select id, text from Record order by timestamp, id")
|
||||||
|
@NamedEntityGraph(name = "CompleteRecord",
|
||||||
|
includeAllAttributes = true)
|
||||||
|
@Entity
|
||||||
|
public class Record {
|
||||||
|
@Id @GeneratedValue
|
||||||
|
String id;
|
||||||
|
String text;
|
||||||
|
LocalDateTime timestamp = LocalDateTime.now();
|
||||||
|
Record() {}
|
||||||
|
public Record(String text) {
|
||||||
|
this.text = text;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
/*
|
||||||
|
* SPDX-License-Identifier: LGPL-2.1-or-later
|
||||||
|
* Copyright Red Hat Inc. and Hibernate Authors
|
||||||
|
*/
|
||||||
|
package org.hibernate.orm.test.jpa.metadata;
|
||||||
|
|
||||||
|
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
|
||||||
|
import org.hibernate.testing.orm.junit.Jpa;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
@Jpa(annotatedClasses = Record.class)
|
||||||
|
public class TypesafeNamedQueryTest {
|
||||||
|
@Test void test(EntityManagerFactoryScope scope) {
|
||||||
|
scope.inTransaction( entityManager -> {
|
||||||
|
Record record1 = new Record("Hello, World!");
|
||||||
|
Record record2 = new Record("Goodbye!");
|
||||||
|
entityManager.persist(record1);
|
||||||
|
entityManager.persist(record2);
|
||||||
|
String text = entityManager.createQuery(Record_._TextById_).setParameter(1, record1.id).getSingleResult();
|
||||||
|
assertEquals("Hello, World!", text);
|
||||||
|
List<Record> all = entityManager.createQuery(Record_._AllRecords_).getResultList();
|
||||||
|
assertEquals(2, all.size());
|
||||||
|
List<Object[]> tuples = entityManager.createQuery(Record_._AllRecordsAsTuples_).getResultList();
|
||||||
|
assertEquals(2, all.size());
|
||||||
|
assertEquals(tuples.get(0)[0], record1.id);
|
||||||
|
assertEquals(tuples.get(1)[1], record2.text);
|
||||||
|
Record record = entityManager.find(Record_._CompleteRecord, record2.id);
|
||||||
|
assertEquals("Goodbye!", record.text);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue