Skip to content

Commit adcc54f

Browse files
committed
HHH-14487 Fix usage of wrong Map in PropertyAccessStrategyMapImpl
1 parent e4e3573 commit adcc54f

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyMapImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
*/
77
package org.hibernate.property.access.internal;
88

9-
import org.hibernate.mapping.Map;
9+
import java.util.Map;
10+
1011
import org.hibernate.property.access.spi.PropertyAccess;
1112
import org.hibernate.property.access.spi.PropertyAccessStrategy;
1213

@@ -24,7 +25,7 @@ public class PropertyAccessStrategyMapImpl implements PropertyAccessStrategy {
2425
public PropertyAccess buildPropertyAccess(Class containerJavaType, String propertyName) {
2526

2627
// Sometimes containerJavaType is null, but if it isn't, make sure it's a Map.
27-
if (containerJavaType != null && !Map.class.isAssignableFrom(containerJavaType)) {
28+
if (containerJavaType != null && !Map.class.isAssignableFrom( containerJavaType)) {
2829
throw new IllegalArgumentException(
2930
String.format(
3031
"Expecting class: [%1$s], but containerJavaType is of type: [%2$s] for propertyName: [%3$s]",

hibernate-core/src/test/java/org/hibernate/property/PropertyAccessStrategyMapTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
import java.util.Date;
1010
import java.util.HashMap;
11+
import java.util.Map;
1112

12-
import org.hibernate.mapping.Map;
1313
import org.hibernate.property.access.internal.PropertyAccessStrategyMapImpl;
1414
import org.hibernate.property.access.spi.PropertyAccess;
1515

@@ -42,7 +42,7 @@ public void testNonMap() {
4242
}
4343
catch (IllegalArgumentException e) {
4444
assertEquals(
45-
"Expecting class: [org.hibernate.mapping.Map], but containerJavaType is of type: [java.util.Date] for propertyName: [time]",
45+
"Expecting class: [java.util.Map], but containerJavaType is of type: [java.util.Date] for propertyName: [time]",
4646
e.getMessage()
4747
);
4848
}

hibernate-core/src/test/java/org/hibernate/test/sql/hand/query/NativeSQLQueriesTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.hibernate.testing.FailureExpected;
4343
import org.hibernate.testing.RequiresDialect;
4444
import org.hibernate.testing.SkipForDialect;
45+
import org.hibernate.testing.TestForIssue;
4546
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
4647
import org.hibernate.test.sql.hand.Dimension;
4748
import org.hibernate.test.sql.hand.Employment;
@@ -885,6 +886,28 @@ public void testEscapeColonInSQL() throws QueryException {
885886
s.close();
886887
}
887888

889+
@Test
890+
@TestForIssue( jiraKey = "HHH-14487")
891+
public void testAliasToBeanMap() {
892+
Person gavin = new Person( "Gavin" );
893+
894+
Session s = openSession();
895+
Transaction t = s.beginTransaction();
896+
s.persist( gavin );
897+
t.commit();
898+
s.close();
899+
900+
s = openSession();
901+
t = s.beginTransaction();
902+
HashMap result = (HashMap) session.createNativeQuery( "select * from PERSON" )
903+
.setResultTransformer( Transformers.aliasToBean( HashMap.class ) )
904+
.uniqueResult();
905+
assertEquals( "Gavin", result.get( "NAME" ) == null ? result.get( "name" ) : result.get( "NAME" ) );
906+
session.delete( gavin );
907+
t.commit();
908+
s.close();
909+
}
910+
888911
private String buildLongString(int size, char baseChar) {
889912
StringBuilder buff = new StringBuilder();
890913
for( int i = 0; i < size; i++ ) {

0 commit comments

Comments
 (0)