Skip to content

Commit 8757ee4

Browse files
dreab8gsmet
authored andcommitted
HHH-12776 Add test for issue
1 parent daef4b7 commit 8757ee4

File tree

3 files changed

+144
-0
lines changed

3 files changed

+144
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5+
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
6+
*/
7+
package org.hibernate.envers.test.integration.nativequery;
8+
9+
import java.util.List;
10+
import javax.persistence.Query;
11+
12+
import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase;
13+
import org.hibernate.envers.test.Priority;
14+
15+
import org.hibernate.testing.TestForIssue;
16+
import org.junit.Test;
17+
18+
import static org.hamcrest.core.Is.is;
19+
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
20+
import static org.junit.Assert.assertThat;
21+
22+
/**
23+
* @author Andrea Boriero
24+
*/
25+
public class EntityResultNativeQueryTest extends BaseEnversJPAFunctionalTestCase {
26+
27+
@Override
28+
protected Class<?>[] getAnnotatedClasses() {
29+
return new Class[] { SimpleEntity.class, SecondSimpleEntity.class };
30+
}
31+
32+
@Test
33+
@Priority(10)
34+
public void initData() {
35+
doInJPA( this::entityManagerFactory, entityManager -> {
36+
entityManager.persist( new SimpleEntity( "Hibernate" ) );
37+
} );
38+
}
39+
40+
@Test
41+
@TestForIssue(jiraKey = "HHH-12776")
42+
public void testNativeQueryResultHandling() {
43+
doInJPA( this::entityManagerFactory, entityManager -> {
44+
Query query = entityManager.createNativeQuery( "select * from SimpleEntity", SimpleEntity.class );
45+
List results = query.getResultList();
46+
SimpleEntity result = (SimpleEntity) results.get( 0 );
47+
assertThat( result.getStringField(), is( "Hibernate" ) );
48+
} );
49+
}
50+
51+
}
52+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5+
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
6+
*/
7+
package org.hibernate.envers.test.integration.nativequery;
8+
9+
import javax.persistence.Entity;
10+
import javax.persistence.GeneratedValue;
11+
import javax.persistence.Id;
12+
13+
import org.hibernate.envers.Audited;
14+
15+
/**
16+
* @author Andrea Boriero
17+
*/
18+
@Audited
19+
@Entity
20+
public class SecondSimpleEntity {
21+
@Id
22+
@GeneratedValue
23+
private Long id;
24+
25+
private String stringField;
26+
27+
public SecondSimpleEntity() {
28+
}
29+
30+
public SecondSimpleEntity(String stringField) {
31+
this.stringField = stringField;
32+
}
33+
34+
public Long getId() {
35+
return id;
36+
}
37+
38+
public String getStringField() {
39+
return stringField;
40+
}
41+
42+
public void setStringField(String stringField) {
43+
this.stringField = stringField;
44+
}
45+
}
46+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5+
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
6+
*/
7+
package org.hibernate.envers.test.integration.nativequery;
8+
9+
import javax.persistence.Entity;
10+
import javax.persistence.GeneratedValue;
11+
import javax.persistence.Id;
12+
13+
import org.hibernate.envers.Audited;
14+
15+
/**
16+
* @author Andrea Boriero
17+
*/
18+
@Entity(name = "SimpleEntity")
19+
@Audited
20+
public class SimpleEntity {
21+
@Id
22+
@GeneratedValue
23+
private Long id;
24+
25+
private String stringField;
26+
27+
public SimpleEntity() {
28+
}
29+
30+
public SimpleEntity(String stringField) {
31+
this.stringField = stringField;
32+
}
33+
34+
public Long getId() {
35+
return id;
36+
}
37+
38+
public String getStringField() {
39+
return stringField;
40+
}
41+
42+
public void setStringField(String stringField) {
43+
this.stringField = stringField;
44+
}
45+
}
46+

0 commit comments

Comments
 (0)