HHH-17208 Add test for issue
This commit is contained in:
parent
41103a60b9
commit
867e93b0c8
|
@ -21,6 +21,7 @@ import org.junit.jupiter.api.Test;
|
||||||
import jakarta.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.FetchType;
|
import jakarta.persistence.FetchType;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import jakarta.persistence.JoinColumn;
|
import jakarta.persistence.JoinColumn;
|
||||||
import jakarta.persistence.Tuple;
|
import jakarta.persistence.Tuple;
|
||||||
|
@ -35,12 +36,13 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
AnyExplicitSelectTest.DocClientEntity.class,
|
AnyExplicitSelectTest.DocClientEntity.class,
|
||||||
} )
|
} )
|
||||||
@SessionFactory
|
@SessionFactory
|
||||||
|
@Jira( "https://hibernate.atlassian.net/browse/HHH-17208" )
|
||||||
@Jira( "https://hibernate.atlassian.net/browse/HHH-17211" )
|
@Jira( "https://hibernate.atlassian.net/browse/HHH-17211" )
|
||||||
public class AnyExplicitSelectTest {
|
public class AnyExplicitSelectTest {
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public void setUp(SessionFactoryScope scope) {
|
public void setUp(SessionFactoryScope scope) {
|
||||||
scope.inTransaction( session -> {
|
scope.inTransaction( session -> {
|
||||||
final DocClientEntity docClientEntity = new DocClientEntity( 1L, "test_client" );
|
final DocClientEntity docClientEntity = new DocClientEntity( "test_client" );
|
||||||
session.persist( docClientEntity );
|
session.persist( docClientEntity );
|
||||||
final DocumentEntity documentEntity = new DocumentEntity( 1L, "test_document" );
|
final DocumentEntity documentEntity = new DocumentEntity( 1L, "test_document" );
|
||||||
documentEntity.setParent( docClientEntity );
|
documentEntity.setParent( docClientEntity );
|
||||||
|
@ -52,7 +54,7 @@ public class AnyExplicitSelectTest {
|
||||||
public void testSelectAny(SessionFactoryScope scope) {
|
public void testSelectAny(SessionFactoryScope scope) {
|
||||||
scope.inTransaction( session -> {
|
scope.inTransaction( session -> {
|
||||||
final IDocumentEntity result = session.createQuery(
|
final IDocumentEntity result = session.createQuery(
|
||||||
"select parent from DocumentEntity",
|
"select parent from DocumentEntity where id = 1",
|
||||||
IDocumentEntity.class
|
IDocumentEntity.class
|
||||||
).getSingleResult();
|
).getSingleResult();
|
||||||
assertThat( result ).isInstanceOf( DocClientEntity.class );
|
assertThat( result ).isInstanceOf( DocClientEntity.class );
|
||||||
|
@ -64,7 +66,7 @@ public class AnyExplicitSelectTest {
|
||||||
public void testSelectTuple(SessionFactoryScope scope) {
|
public void testSelectTuple(SessionFactoryScope scope) {
|
||||||
scope.inTransaction( session -> {
|
scope.inTransaction( session -> {
|
||||||
final Tuple result = session.createQuery(
|
final Tuple result = session.createQuery(
|
||||||
"select id, name, parent from DocumentEntity",
|
"select id, name, parent from DocumentEntity where id = 1",
|
||||||
Tuple.class
|
Tuple.class
|
||||||
).getSingleResult();
|
).getSingleResult();
|
||||||
assertThat( result.get( 0, Long.class ) ).isEqualTo( 1L );
|
assertThat( result.get( 0, Long.class ) ).isEqualTo( 1L );
|
||||||
|
@ -73,6 +75,31 @@ public class AnyExplicitSelectTest {
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInsertSelect(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction( session -> {
|
||||||
|
final int count = session.createMutationQuery(
|
||||||
|
"insert into DocumentEntity(id, name, parent) " +
|
||||||
|
"select id+1, name, parent from DocumentEntity where name = 'test_document'"
|
||||||
|
).executeUpdate();
|
||||||
|
assertThat( count ).isEqualTo( 1 );
|
||||||
|
} );
|
||||||
|
scope.inTransaction( session -> assertThat(
|
||||||
|
session.createQuery( "from DocumentEntity", DocumentEntity.class ).getResultList()
|
||||||
|
).hasSize( 2 ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTypeSelect(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction( session -> {
|
||||||
|
final Object result = session.createQuery(
|
||||||
|
"select type(d.parent) from DocumentEntity d where id = 1",
|
||||||
|
Object.class
|
||||||
|
).getSingleResult();
|
||||||
|
assertThat( result ).isEqualTo( "doc_client" );
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
public interface IDocumentEntity {
|
public interface IDocumentEntity {
|
||||||
Long getId();
|
Long getId();
|
||||||
|
|
||||||
|
@ -120,6 +147,7 @@ public class AnyExplicitSelectTest {
|
||||||
@Entity( name = "DocClientEntity" )
|
@Entity( name = "DocClientEntity" )
|
||||||
public static class DocClientEntity implements IDocumentEntity {
|
public static class DocClientEntity implements IDocumentEntity {
|
||||||
@Id
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
@ -127,8 +155,7 @@ public class AnyExplicitSelectTest {
|
||||||
public DocClientEntity() {
|
public DocClientEntity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public DocClientEntity(Long id, String name) {
|
public DocClientEntity(String name) {
|
||||||
this.id = id;
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue