HHH-14975 - Allow use of auto-applied AttributeConverter as native-query result or parameter

This commit is contained in:
Steve Ebersole 2021-12-12 15:47:57 -06:00
parent 38fa2aef75
commit fcda293c5e
1 changed files with 29 additions and 0 deletions

View File

@ -22,9 +22,13 @@ import jakarta.persistence.Table;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.query.NativeQuery;
import org.hibernate.query.sql.spi.NativeQueryImplementor;
import org.hibernate.testing.FailureExpected;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
import org.hibernate.testing.orm.junit.JiraKey;
import org.hibernate.testing.orm.junit.NotImplementedYet;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -63,6 +67,7 @@ public class QueryTest extends BaseNonConfigCoreFunctionalTestCase {
}
@Test
@JiraKey( "HHH-13082" )
public void testNativeQueryResult() {
inTransaction( (session) -> {
final NativeQueryImplementor<Object[]> query = session.createNativeQuery( "select id, salary from EMP", "emp_id_salary" );
@ -76,6 +81,23 @@ public class QueryTest extends BaseNonConfigCoreFunctionalTestCase {
} );
}
@Test
@FailureExpected( jiraKey = "HHH-14975", message = "Not yet implemented" )
@NotImplementedYet
@JiraKey( "HHH-14975" )
public void testAutoAppliedConverterAsNativeQueryResult() {
inTransaction( (session) -> {
final NativeQueryImplementor<Object[]> query = session.createNativeQuery( "select id, salary from EMP", "emp_id_salary2" );
final List<Object[]> results = query.list();
assertThat( results ).hasSize( 1 );
final Object[] values = results.get( 0 );
assertThat( values[0] ).isEqualTo( 1 );
assertThat( values[1] ).isEqualTo( SALARY );
} );
}
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[] { Employee.class, SalaryConverter.class };
@ -108,6 +130,13 @@ public class QueryTest extends BaseNonConfigCoreFunctionalTestCase {
@ColumnResult( name = "salary", type = SalaryConverter.class )
}
)
@SqlResultSetMapping(
name = "emp_id_salary2",
columns = {
@ColumnResult( name = "id" ),
@ColumnResult( name = "salary", type = Float.class )
}
)
public static class Employee {
@Id
public Integer id;