diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/any/annotations/AnyExplicitSelectTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/any/annotations/AnyExplicitSelectTest.java index 40c8966107..8d4b2e4aaa 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/any/annotations/AnyExplicitSelectTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/any/annotations/AnyExplicitSelectTest.java @@ -21,6 +21,7 @@ import org.junit.jupiter.api.Test; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.Tuple; @@ -35,12 +36,13 @@ import static org.assertj.core.api.Assertions.assertThat; AnyExplicitSelectTest.DocClientEntity.class, } ) @SessionFactory +@Jira( "https://hibernate.atlassian.net/browse/HHH-17208" ) @Jira( "https://hibernate.atlassian.net/browse/HHH-17211" ) public class AnyExplicitSelectTest { @BeforeAll public void setUp(SessionFactoryScope scope) { scope.inTransaction( session -> { - final DocClientEntity docClientEntity = new DocClientEntity( 1L, "test_client" ); + final DocClientEntity docClientEntity = new DocClientEntity( "test_client" ); session.persist( docClientEntity ); final DocumentEntity documentEntity = new DocumentEntity( 1L, "test_document" ); documentEntity.setParent( docClientEntity ); @@ -52,7 +54,7 @@ public class AnyExplicitSelectTest { public void testSelectAny(SessionFactoryScope scope) { scope.inTransaction( session -> { final IDocumentEntity result = session.createQuery( - "select parent from DocumentEntity", + "select parent from DocumentEntity where id = 1", IDocumentEntity.class ).getSingleResult(); assertThat( result ).isInstanceOf( DocClientEntity.class ); @@ -64,7 +66,7 @@ public class AnyExplicitSelectTest { public void testSelectTuple(SessionFactoryScope scope) { scope.inTransaction( session -> { final Tuple result = session.createQuery( - "select id, name, parent from DocumentEntity", + "select id, name, parent from DocumentEntity where id = 1", Tuple.class ).getSingleResult(); 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 { Long getId(); @@ -120,6 +147,7 @@ public class AnyExplicitSelectTest { @Entity( name = "DocClientEntity" ) public static class DocClientEntity implements IDocumentEntity { @Id + @GeneratedValue private Long id; private String name; @@ -127,8 +155,7 @@ public class AnyExplicitSelectTest { public DocClientEntity() { } - public DocClientEntity(Long id, String name) { - this.id = id; + public DocClientEntity(String name) { this.name = name; }