diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/nativequery/EntityResultNativeQueryTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/nativequery/EntityResultNativeQueryTest.java new file mode 100644 index 0000000000..bb117086f4 --- /dev/null +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/nativequery/EntityResultNativeQueryTest.java @@ -0,0 +1,52 @@ +/* + * 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 . + */ +package org.hibernate.envers.test.integration.nativequery; + +import java.util.List; +import javax.persistence.Query; + +import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; +import org.hibernate.envers.test.Priority; + +import org.hibernate.testing.TestForIssue; +import org.junit.Test; + +import static org.hamcrest.core.Is.is; +import static org.hibernate.testing.transaction.TransactionUtil.doInJPA; +import static org.junit.Assert.assertThat; + +/** + * @author Andrea Boriero + */ +public class EntityResultNativeQueryTest extends BaseEnversJPAFunctionalTestCase { + + @Override + protected Class[] getAnnotatedClasses() { + return new Class[] { SimpleEntity.class, SecondSimpleEntity.class }; + } + + @Test + @Priority(10) + public void initData() { + doInJPA( this::entityManagerFactory, entityManager -> { + entityManager.persist( new SimpleEntity( "Hibernate" ) ); + } ); + } + + @Test + @TestForIssue(jiraKey = "HHH-12776") + public void testNativeQueryResultHandling() { + doInJPA( this::entityManagerFactory, entityManager -> { + Query query = entityManager.createNativeQuery( "select * from SimpleEntity", SimpleEntity.class ); + List results = query.getResultList(); + SimpleEntity result = (SimpleEntity) results.get( 0 ); + assertThat( result.getStringField(), is( "Hibernate" ) ); + } ); + } + +} + diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/nativequery/SecondSimpleEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/nativequery/SecondSimpleEntity.java new file mode 100644 index 0000000000..3fd9f8249e --- /dev/null +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/nativequery/SecondSimpleEntity.java @@ -0,0 +1,46 @@ +/* + * 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 . + */ +package org.hibernate.envers.test.integration.nativequery; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +import org.hibernate.envers.Audited; + +/** + * @author Andrea Boriero + */ +@Audited +@Entity +public class SecondSimpleEntity { + @Id + @GeneratedValue + private Long id; + + private String stringField; + + public SecondSimpleEntity() { + } + + public SecondSimpleEntity(String stringField) { + this.stringField = stringField; + } + + public Long getId() { + return id; + } + + public String getStringField() { + return stringField; + } + + public void setStringField(String stringField) { + this.stringField = stringField; + } +} + diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/nativequery/SimpleEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/nativequery/SimpleEntity.java new file mode 100644 index 0000000000..e8d3e79fea --- /dev/null +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/nativequery/SimpleEntity.java @@ -0,0 +1,46 @@ +/* + * 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 . + */ +package org.hibernate.envers.test.integration.nativequery; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +import org.hibernate.envers.Audited; + +/** + * @author Andrea Boriero + */ +@Entity(name = "SimpleEntity") +@Audited +public class SimpleEntity { + @Id + @GeneratedValue + private Long id; + + private String stringField; + + public SimpleEntity() { + } + + public SimpleEntity(String stringField) { + this.stringField = stringField; + } + + public Long getId() { + return id; + } + + public String getStringField() { + return stringField; + } + + public void setStringField(String stringField) { + this.stringField = stringField; + } +} +