Skip to content

Commit f2e0f46

Browse files
committed
HHH-15283 - fix NPE for NamedNativeQuery + SqlResultSetMapping (columns)
1 parent 673514b commit f2e0f46

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderBasicValuedStandard.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public boolean equals(Object o) {
166166
if ( !Objects.equals( explicitType, that.explicitType ) ) {
167167
return false;
168168
}
169-
return explicitJavaType.equals( that.explicitJavaType );
169+
return Objects.equals( explicitJavaType, that.explicitJavaType );
170170
}
171171

172172
@Override

hibernate-core/src/test/java/org/hibernate/orm/test/query/resultmapping/NamedNativeQueryWithCountColumnTest.java

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,18 @@
1212
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
1313
import org.hibernate.testing.orm.junit.Jpa;
1414
import org.hibernate.testing.orm.junit.Setting;
15+
import org.junit.jupiter.api.BeforeEach;
1516
import org.junit.jupiter.api.Test;
1617

1718
import jakarta.persistence.ColumnResult;
1819
import jakarta.persistence.Entity;
1920
import jakarta.persistence.Id;
2021
import jakarta.persistence.NamedNativeQuery;
2122
import jakarta.persistence.SqlResultSetMapping;
23+
import jakarta.persistence.Table;
24+
25+
import static org.hamcrest.CoreMatchers.is;
26+
import static org.hamcrest.MatcherAssert.assertThat;
2227

2328
/**
2429
* @author Nathan Xu
@@ -30,25 +35,50 @@
3035
@TestForIssue(jiraKey = "HHH-15070")
3136
class NamedNativeQueryWithCountColumnTest {
3237

38+
@BeforeEach
39+
public void setUp(EntityManagerFactoryScope scope) {
40+
scope.inTransaction(
41+
entityManager -> {
42+
for ( int i = 0; i < 3; i++ ) {
43+
Sample sample = new Sample( i, String.valueOf( i ) );
44+
entityManager.persist( sample );
45+
}
46+
}
47+
);
48+
}
49+
3350
@Test
34-
void testNoNullPointerExceptionThrown(EntityManagerFactoryScope scope) {
35-
scope.inTransaction( em ->em.createNamedQuery( "sample.count", Long.class ) );
51+
void testNamedNativeQuery(EntityManagerFactoryScope scope) {
52+
scope.inTransaction( em -> {
53+
Long count = em.createNamedQuery( "sample.count", Long.class ).getSingleResult();
54+
assertThat( count, is( 3l ) );
55+
} );
3656
}
3757

3858
@SqlResultSetMapping(
39-
name = "mapping",
40-
columns = @ColumnResult( name = "cnt" )
59+
name = "mapping",
60+
columns = @ColumnResult(name = "cnt")
4161
)
4262
@NamedNativeQuery(
43-
name = "sample.count",
44-
resultSetMapping = "mapping",
45-
query = "SELECT count(*) AS cnt FROM Sample"
63+
name = "sample.count",
64+
resultSetMapping = "mapping",
65+
query = "SELECT count(*) AS cnt FROM SAMPLE_TABLE"
4666
)
4767
@Entity(name = "Sample")
68+
@Table(name = "SAMPLE_TABLE")
4869
static class Sample {
4970

5071
@Id
51-
Long id;
72+
Integer id;
73+
74+
String name;
75+
76+
public Sample() {
77+
}
5278

79+
public Sample(Integer id, String name) {
80+
this.id = id;
81+
this.name = name;
82+
}
5383
}
5484
}

0 commit comments

Comments
 (0)