-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Recommend sql-query return scalar vals, & query cache ch
PostPosted: Mon Nov 07, 2005 2:19 pm 
Regular
Regular

Joined: Thu Dec 02, 2004 10:42 am
Posts: 54
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?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 07, 2005 5:12 pm 
Regular
Regular

Joined: Thu Dec 02, 2004 10:42 am
Posts: 54
Even modifing the query cache cannot be done very soon, I recommend to add that the feature for sql-query supporting scalar return value. It's just one little modification in SqlLoader.cs, as described above.

For using it:
Code:
  query = session.CreateSQLQuery(sqlStr, new string[]{}, new Type[]{});


This will allow us to use other IQuery easy to use methods: query.SetMaxResults(), SetFirstResutl(), etc. Just the return scalar values are not in correct types, i.e. all number return as decimal for Oracle. If NHibernate1.0 can allow we put scalar types in session.CreateSQLQuery(), it will be better. Is this very hard to implement? It dosenot seem like that hard. :)

Will there be a patch for NHibernate 1.0, can this feature get included? Or you guys are just concentrating migrating Hibernate3 from now on?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 07, 2005 5:38 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Please create a JIRA issue for this. In the meantime, you can either implement it in your copy of NHibernate and use that, or implement your own SQL query cache, this should not be hard.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.