Currently, we don't have the <return-scalar> for <sql-query>, that is Hibernate 3.x feature. HQL can return scalar values, but our group really need native query return one, cause:
1. we have to use native query for some oracle native feature
2. the query return 10,000 records, which we don't want NHibernate to cache or even use reflection to get the results into objects, cause it's slow with reflection.
3. But we do like the query cache can handle the 2nd same SQL, just return the result set from cache immediatly. No need to return objects.
I found solving 1 & 2 is easy by modifying SqlLoader.cs:
Code:
protected override object GetResultColumnOrRow( object[ ] row, IDataReader rs, ISessionImplementor session )
{
if( Persisters.Length == 1 )
{
return row[ row.Length - 1 ];
}
else
{
row = new object[rs.FieldCount];
for( int i = 0; i < row.Length; i++ )
{
object obj = rs[i];
if (obj is DBNull)
{
obj = null;
}
row[i] = obj;
}
return row;
}
}
But, besides using NHibernate's session and DB conenction, independant with different DB driver, it's really not THAT useful. I can just use session.Connection.CreateCommand() to call the native query. So, what I hope is , for query cache, if the return is scalar values, automatically cache the result set or the collection of data.
Is it easy to modify the query cache part?