HHH-14487 Fix usage of wrong Map in PropertyAccessStrategyMapImpl
This commit is contained in:
parent
c57d394445
commit
2894f84d6e
|
@ -6,7 +6,8 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.property.access.internal;
|
package org.hibernate.property.access.internal;
|
||||||
|
|
||||||
import org.hibernate.mapping.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.hibernate.property.access.spi.PropertyAccess;
|
import org.hibernate.property.access.spi.PropertyAccess;
|
||||||
import org.hibernate.property.access.spi.PropertyAccessStrategy;
|
import org.hibernate.property.access.spi.PropertyAccessStrategy;
|
||||||
|
|
||||||
|
@ -24,7 +25,7 @@ public class PropertyAccessStrategyMapImpl implements PropertyAccessStrategy {
|
||||||
public PropertyAccess buildPropertyAccess(Class containerJavaType, String propertyName, boolean setterRequired) {
|
public PropertyAccess buildPropertyAccess(Class containerJavaType, String propertyName, boolean setterRequired) {
|
||||||
|
|
||||||
// Sometimes containerJavaType is null, but if it isn't, make sure it's a Map.
|
// Sometimes containerJavaType is null, but if it isn't, make sure it's a Map.
|
||||||
if (containerJavaType != null && !Map.class.isAssignableFrom(containerJavaType)) {
|
if (containerJavaType != null && !Map.class.isAssignableFrom( containerJavaType)) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
String.format(
|
String.format(
|
||||||
"Expecting class: [%1$s], but containerJavaType is of type: [%2$s] for propertyName: [%3$s]",
|
"Expecting class: [%1$s], but containerJavaType is of type: [%2$s] for propertyName: [%3$s]",
|
||||||
|
|
|
@ -8,8 +8,8 @@ package org.hibernate.orm.test.property;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.hibernate.mapping.Map;
|
|
||||||
import org.hibernate.property.access.internal.PropertyAccessStrategyMapImpl;
|
import org.hibernate.property.access.internal.PropertyAccessStrategyMapImpl;
|
||||||
import org.hibernate.property.access.spi.PropertyAccess;
|
import org.hibernate.property.access.spi.PropertyAccess;
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ public class PropertyAccessStrategyMapTest extends BaseUnitTestCase {
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException e) {
|
catch (IllegalArgumentException e) {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"Expecting class: [org.hibernate.mapping.Map], but containerJavaType is of type: [java.util.Date] for propertyName: [time]",
|
"Expecting class: [java.util.Map], but containerJavaType is of type: [java.util.Date] for propertyName: [time]",
|
||||||
e.getMessage()
|
e.getMessage()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,7 @@ import org.hibernate.transform.ResultTransformer;
|
||||||
import org.hibernate.transform.Transformers;
|
import org.hibernate.transform.Transformers;
|
||||||
import org.hibernate.type.StandardBasicTypes;
|
import org.hibernate.type.StandardBasicTypes;
|
||||||
|
|
||||||
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.hibernate.testing.orm.junit.DomainModel;
|
import org.hibernate.testing.orm.junit.DomainModel;
|
||||||
import org.hibernate.testing.orm.junit.FailureExpected;
|
import org.hibernate.testing.orm.junit.FailureExpected;
|
||||||
import org.hibernate.testing.orm.junit.RequiresDialect;
|
import org.hibernate.testing.orm.junit.RequiresDialect;
|
||||||
|
@ -911,6 +912,26 @@ public class NativeSQLQueriesTest {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestForIssue( jiraKey = "HHH-14487")
|
||||||
|
public void testAliasToBeanMap(SessionFactoryScope scope) {
|
||||||
|
Person gavin = new Person( "Gavin" );
|
||||||
|
|
||||||
|
scope.inTransaction(
|
||||||
|
session -> session.persist( gavin )
|
||||||
|
);
|
||||||
|
|
||||||
|
scope.inTransaction(
|
||||||
|
session -> {
|
||||||
|
HashMap result = (HashMap) session.createNativeQuery( "select * from PERSON" )
|
||||||
|
.setResultTransformer( Transformers.aliasToBean( HashMap.class ) )
|
||||||
|
.uniqueResult();
|
||||||
|
assertEquals( "Gavin", result.get( "NAME" ) == null ? result.get( "name" ) : result.get( "NAME" ) );
|
||||||
|
session.delete( gavin );
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private String buildLongString(int size, char baseChar) {
|
private String buildLongString(int size, char baseChar) {
|
||||||
StringBuilder buff = new StringBuilder();
|
StringBuilder buff = new StringBuilder();
|
||||||
for( int i = 0; i < size; i++ ) {
|
for( int i = 0; i < size; i++ ) {
|
||||||
|
|
Loading…
Reference in New Issue