HHH-14487 Fix usage of wrong Map in PropertyAccessStrategyMapImpl

This commit is contained in:
Christian Beikov 2022-03-18 11:52:04 +01:00
parent e4e35732da
commit adcc54febd
3 changed files with 28 additions and 4 deletions

View File

@ -6,7 +6,8 @@
*/
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.PropertyAccessStrategy;

View File

@ -8,8 +8,8 @@ package org.hibernate.property;
import java.util.Date;
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.spi.PropertyAccess;
@ -42,7 +42,7 @@ public class PropertyAccessStrategyMapTest extends BaseUnitTestCase {
}
catch (IllegalArgumentException e) {
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()
);
}

View File

@ -42,6 +42,7 @@ import org.hibernate.type.TimestampType;
import org.hibernate.testing.FailureExpected;
import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.SkipForDialect;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.hibernate.test.sql.hand.Dimension;
import org.hibernate.test.sql.hand.Employment;
@ -885,6 +886,28 @@ public class NativeSQLQueriesTest extends BaseCoreFunctionalTestCase {
s.close();
}
@Test
@TestForIssue( jiraKey = "HHH-14487")
public void testAliasToBeanMap() {
Person gavin = new Person( "Gavin" );
Session s = openSession();
Transaction t = s.beginTransaction();
s.persist( gavin );
t.commit();
s.close();
s = openSession();
t = s.beginTransaction();
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 );
t.commit();
s.close();
}
private String buildLongString(int size, char baseChar) {
StringBuilder buff = new StringBuilder();
for( int i = 0; i < size; i++ ) {