mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-03-01 15:29:11 +00:00
HHH-16488 Add test for issue
This commit is contained in:
parent
279b6ad31f
commit
f32a11fedd
@ -6,20 +6,23 @@
|
|||||||
*/
|
*/
|
||||||
package org.hibernate.orm.test.mapping.onetoone;
|
package org.hibernate.orm.test.mapping.onetoone;
|
||||||
|
|
||||||
|
import org.hibernate.testing.jdbc.SQLStatementInspector;
|
||||||
|
import org.hibernate.testing.orm.junit.DomainModel;
|
||||||
|
import org.hibernate.testing.orm.junit.Jira;
|
||||||
|
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||||
|
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||||
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import jakarta.persistence.ManyToOne;
|
import jakarta.persistence.ManyToOne;
|
||||||
|
import jakarta.persistence.Tuple;
|
||||||
import org.hibernate.testing.jdbc.SQLStatementInspector;
|
|
||||||
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.BeforeEach;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
import static org.hamcrest.Matchers.notNullValue;
|
import static org.hamcrest.Matchers.notNullValue;
|
||||||
|
import static org.hamcrest.Matchers.nullValue;
|
||||||
import static org.hibernate.orm.test.mapping.onetoone.ToOneSelfReferenceTest.EntityTest;
|
import static org.hibernate.orm.test.mapping.onetoone.ToOneSelfReferenceTest.EntityTest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,27 +31,26 @@
|
|||||||
@DomainModel( annotatedClasses = { EntityTest.class } )
|
@DomainModel( annotatedClasses = { EntityTest.class } )
|
||||||
@SessionFactory( useCollectingStatementInspector = true )
|
@SessionFactory( useCollectingStatementInspector = true )
|
||||||
public class ToOneSelfReferenceTest {
|
public class ToOneSelfReferenceTest {
|
||||||
|
@BeforeAll
|
||||||
@BeforeEach
|
|
||||||
public void setUp(SessionFactoryScope scope) {
|
public void setUp(SessionFactoryScope scope) {
|
||||||
scope.inTransaction(
|
scope.inTransaction(
|
||||||
session -> {
|
session -> {
|
||||||
EntityTest entity = new EntityTest( 1, "e1" );
|
final EntityTest entity = new EntityTest( 1, "e1" );
|
||||||
EntityTest entity2 = new EntityTest( 2, "e2" );
|
final EntityTest entity2 = new EntityTest( 2, "e2" );
|
||||||
EntityTest entity3 = new EntityTest( 3, "e3" );
|
final EntityTest entity3 = new EntityTest( 3, "e3" );
|
||||||
|
|
||||||
entity2.setEntity( entity3 );
|
entity2.setEntity( entity3 );
|
||||||
entity.setEntity( entity2 );
|
entity.setEntity( entity2 );
|
||||||
session.save( entity3 );
|
session.persist( entity3 );
|
||||||
session.save( entity2 );
|
session.persist( entity2 );
|
||||||
session.save( entity );
|
session.persist( entity );
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGet(SessionFactoryScope scope) {
|
public void testGet(SessionFactoryScope scope) {
|
||||||
SQLStatementInspector statementInspector = scope.getCollectingStatementInspector();
|
final SQLStatementInspector statementInspector = scope.getCollectingStatementInspector();
|
||||||
statementInspector.clear();
|
statementInspector.clear();
|
||||||
scope.inTransaction(
|
scope.inTransaction(
|
||||||
session -> {
|
session -> {
|
||||||
@ -69,6 +71,50 @@ public void testGet(SessionFactoryScope scope) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Jira( "https://hibernate.atlassian.net/browse/HHH-16488" )
|
||||||
|
public void testJoinIdQuery(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction( session -> {
|
||||||
|
final Tuple result = session.createQuery(
|
||||||
|
"select e1.id, e1.name, e2.id, e2.name from EntityTest e1 join e1.entity e2 where e1.id = 2",
|
||||||
|
Tuple.class
|
||||||
|
).getSingleResult();
|
||||||
|
assertThat( result.get( 0 ), is( 2 ) );
|
||||||
|
assertThat( result.get( 1 ), is( "e2" ) );
|
||||||
|
assertThat( result.get( 2 ), is( 3 ) );
|
||||||
|
assertThat( result.get( 3 ), is( "e3" ) );
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Jira( "https://hibernate.atlassian.net/browse/HHH-16488" )
|
||||||
|
public void testQuery(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction( session -> {
|
||||||
|
final EntityTest result = session.createQuery(
|
||||||
|
"select e from EntityTest e where e.id = 2",
|
||||||
|
EntityTest.class
|
||||||
|
).getSingleResult();
|
||||||
|
assertThat( result.getId(), is( 2 ) );
|
||||||
|
assertThat( result.getName(), is( "e2" ) );
|
||||||
|
assertThat( result.getEntity().getId(), is( 3 ) );
|
||||||
|
assertThat( result.getEntity().getName(), is( "e3" ) );
|
||||||
|
assertThat( result.getEntity().getEntity(), is( nullValue() ) );
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Jira( "https://hibernate.atlassian.net/browse/HHH-16488" )
|
||||||
|
public void testFind(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction( session -> {
|
||||||
|
final EntityTest result = session.find( EntityTest.class, 2 );
|
||||||
|
assertThat( result.getId(), is( 2 ) );
|
||||||
|
assertThat( result.getName(), is( "e2" ) );
|
||||||
|
assertThat( result.getEntity().getId(), is( 3 ) );
|
||||||
|
assertThat( result.getEntity().getName(), is( "e3" ) );
|
||||||
|
assertThat( result.getEntity().getEntity(), is( nullValue() ) );
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
@Entity( name = "EntityTest" )
|
@Entity( name = "EntityTest" )
|
||||||
public static class EntityTest {
|
public static class EntityTest {
|
||||||
@Id
|
@Id
|
||||||
|
Loading…
x
Reference in New Issue
Block a user