-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
105 additions
and
0 deletions.
There are no files selected for viewing
105 changes: 105 additions & 0 deletions
105
...ate-core/src/test/java/org/hibernate/orm/test/query/sql/EmbeddableAndNativeQueryTest.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.orm.test.query.sql; | ||
|
||
import java.util.List; | ||
|
||
import org.hibernate.testing.TestForIssue; | ||
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.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import jakarta.persistence.Embeddable; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
@DomainModel( | ||
annotatedClasses = EmbeddableAndNativeQueryTest.Person.class | ||
) | ||
@SessionFactory | ||
@TestForIssue(jiraKey = "HHH-15658") | ||
public class EmbeddableAndNativeQueryTest { | ||
|
||
@BeforeEach | ||
public void setUp(SessionFactoryScope scope) { | ||
scope.inTransaction( | ||
session -> { | ||
Address address = new Address( "Milan", "Italy", "Italy", "20133" ); | ||
Person person = new Person( 1, address ); | ||
|
||
Address address2 = new Address( "Garbagnate", "Italy", "Italy", "20024" ); | ||
Person person2 = new Person( 2, address2 ); | ||
|
||
session.persist( person ); | ||
session.persist( person2 ); | ||
} | ||
); | ||
} | ||
|
||
@AfterEach | ||
public void tearDown(SessionFactoryScope scope) { | ||
scope.inTransaction( | ||
session -> | ||
session.createMutationQuery( "delete from Person" ).executeUpdate() | ||
); | ||
} | ||
|
||
@Test | ||
public void testSelect(SessionFactoryScope scope) { | ||
scope.inTransaction( | ||
session -> { | ||
List<Person> people = session.createNativeQuery( | ||
"select {p.*} from Person p", | ||
Person.class, | ||
"p" | ||
).list(); | ||
|
||
assertThat( people.size() ).isEqualTo( 2 ); | ||
} | ||
); | ||
} | ||
|
||
@Entity(name = "Person") | ||
public static class Person { | ||
@Id | ||
private Integer id; | ||
|
||
private Address address; | ||
|
||
public Person() { | ||
} | ||
|
||
public Person(Integer id, Address address) { | ||
this.id = id; | ||
this.address = address; | ||
} | ||
} | ||
|
||
@Embeddable | ||
public static class Address { | ||
private String city; | ||
private String state; | ||
private String country; | ||
|
||
private String postcode; | ||
|
||
public Address() { | ||
} | ||
|
||
public Address(String city, String state, String country, String postcode) { | ||
this.city = city; | ||
this.state = state; | ||
this.country = country; | ||
this.postcode = postcode; | ||
} | ||
} | ||
} |