HHH-8850 - fixed ex. when calling addScalar to NamedSQLQuery
changed list instanciation from java.util.Arrays.ArrayList to java.util.ArrayList when creating SQLQueryImpl from an NamedSQLQueryDefinition. added testcase
This commit is contained in:
parent
7c69c7fb95
commit
61c66f1d2c
|
@ -89,10 +89,10 @@ public class SQLQueryImpl extends AbstractQueryImpl implements SQLQuery {
|
|||
queryDef.getResultSetRef()
|
||||
);
|
||||
}
|
||||
this.queryReturns = Arrays.asList( definition.getQueryReturns() );
|
||||
this.queryReturns = new ArrayList<NativeSQLQueryReturn>(Arrays.asList( definition.getQueryReturns() ));
|
||||
}
|
||||
else if ( queryDef.getQueryReturns() != null && queryDef.getQueryReturns().length > 0 ) {
|
||||
this.queryReturns = Arrays.asList( queryDef.getQueryReturns() );
|
||||
this.queryReturns = new ArrayList<NativeSQLQueryReturn>(Arrays.asList( queryDef.getQueryReturns()));
|
||||
}
|
||||
else {
|
||||
this.queryReturns = new ArrayList<NativeSQLQueryReturn>();
|
||||
|
|
|
@ -9,7 +9,6 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.Query;
|
||||
|
@ -22,6 +21,8 @@ import org.hibernate.cfg.Environment;
|
|||
import org.hibernate.dialect.H2Dialect;
|
||||
import org.hibernate.dialect.AbstractHANADialect;
|
||||
import org.hibernate.dialect.MySQL5Dialect;
|
||||
import org.hibernate.engine.query.spi.sql.NativeSQLQueryReturn;
|
||||
import org.hibernate.engine.spi.NamedSQLQueryDefinitionBuilder;
|
||||
import org.hibernate.internal.util.collections.ArrayHelper;
|
||||
import org.hibernate.test.sql.hand.Dimension;
|
||||
import org.hibernate.test.sql.hand.Employment;
|
||||
|
@ -141,6 +142,28 @@ public class NativeSQLQueriesTest extends BaseCoreFunctionalTestCase {
|
|||
s.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegisteredNamedSQLQueryWithScalar()
|
||||
{
|
||||
final NamedSQLQueryDefinitionBuilder builder = new NamedSQLQueryDefinitionBuilder();
|
||||
builder.setName("namedQuery");
|
||||
builder.setQuery("select count(*) AS count from organization");
|
||||
builder.setQueryReturns(new NativeSQLQueryReturn[1]);
|
||||
|
||||
sessionFactory().registerNamedSQLQueryDefinition("namedQuery", builder.createNamedQueryDefinition());
|
||||
|
||||
final Session s = openSession();
|
||||
s.beginTransaction();
|
||||
final SQLQuery query = (SQLQuery) s.getNamedQuery("namedQuery");
|
||||
query.addScalar("count");
|
||||
final Object result = query.uniqueResult();
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
||||
assertNotNull(result);
|
||||
assertEquals(BigInteger.valueOf(0), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testManualSynchronization() {
|
||||
|
|
Loading…
Reference in New Issue