HHH-12776 Add test for issue

This commit is contained in:
Andrea Boriero 2018-07-09 09:44:38 +01:00 committed by Guillaume Smet
parent daef4b7f08
commit 8757ee4191
3 changed files with 144 additions and 0 deletions

View File

@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
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" ) );
} );
}
}

View File

@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
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;
}
}

View File

@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
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;
}
}