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.  [ 9 posts ] 
Author Message
 Post subject: Update Help Required!!!
PostPosted: Mon Nov 20, 2006 10:17 am 
Beginner
Beginner

Joined: Wed Aug 30, 2006 2:06 am
Posts: 24
I want to use sql query to update couple of columns in a table.
I am using native query to do it.

My sample query looks like this.

ISQLQuery query = session.CreateSQLQuery("Update VcsSpm_SupplierMstr set SupplierStatus = 'F' where SupplierCode = 'S001'");

When executing this query i am getting the below exception.

"Return types of SQL query were not specified"

Any help in this regard is appreciated.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 20, 2006 10:33 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
NHibernate does not support update queries in CreateSQLQuery. Execute the query using the ADO.NET API.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 21, 2006 9:13 am 
Newbie

Joined: Mon Nov 20, 2006 2:06 am
Posts: 7
Append something like "Select @@rowCount as noOfRowsAfftected" to your query and this will probably work.

However, this may not be a recommended approach.

Regards,
Indrajeet


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 21, 2006 1:34 pm 
Beginner
Beginner

Joined: Wed Aug 30, 2006 2:06 am
Posts: 24
What is the approach i need to take if i want to do partial update in a table using NHibernate.
If my requirement is that i need to update only status column in a particular table, is it possible using NHibernate APIs???


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 22, 2006 7:00 am 
Newbie

Joined: Mon Nov 20, 2006 2:06 am
Posts: 7
I could not come across any approach using nHibernate APIs.

I am aware of only one approach(workaround) which we have already discussed here...
Through ISQLQuery interface as you have done in your first post. You will need to append the Select query to it (as I mentioned in my previous post).


Regards,
Indrajeet


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 07, 2007 11:44 pm 
Beginner
Beginner

Joined: Fri Jan 12, 2007 1:08 am
Posts: 41
Actually with a little creativity this can be made to work:

Code:
ISQLQuery q =session.CreateSQLQuery("blah blah blah");
q.AddScalar("ignored", NHibernateUtil.Int32);
q.UniqueResult();



Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 24, 2007 3:54 pm 
Beginner
Beginner

Joined: Fri Jan 12, 2007 1:08 am
Posts: 41
Note that technique that I suggested above does not work with all databases. It does work with SQL Server but it did not work for SQL Anywhere 10 (I wrote a custom Driver - I'll contribute it to the project). The workaround was to use a combination of my approach and the suggestion made by IndrajeetP:

Code:
ISQLQuery q = _session.CreateSQLQuery("DELETE FROM t1 select 1 IgnoreMe");
q.AddScalar("IgnoreMe", NHibernateUtil.Int32);
q.UniqueResult();

Of course it would be wonderful if ISQLQuery contained an Execute() / NoResult() method. If other people think that this would be useful then I can look into adding this.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 13, 2008 1:58 pm 
Newbie

Joined: Fri Jun 13, 2008 1:52 pm
Posts: 1
jagid wrote:
Note that technique that I suggested above does not work with all databases. It does work with SQL Server but it did not work for SQL Anywhere 10 (I wrote a custom Driver - I'll contribute it to the project). The workaround was to use a combination of my approach and the suggestion made by IndrajeetP:

Code:
ISQLQuery q = _session.CreateSQLQuery("DELETE FROM t1 select 1 IgnoreMe");
q.AddScalar("IgnoreMe", NHibernateUtil.Int32);
q.UniqueResult();

Of course it would be wonderful if ISQLQuery contained an Execute() / NoResult() method. If other people think that this would be useful then I can look into adding this.


Hi, I m trying to execute Select statment like
ISQLQuery sql = _session.CreateSQLQuery("select count(*) from PD4Log");
sql.AddScalar("xyz", NHibernateUtil.Int32);

string _results = sql.SetFirstResult(0).UniqueResult().ToString();

and it show the following error
System.IndexOutOfRangeException
Please reply how to execute any select stament and get the result in Nhibernate.
Thanks
Mukesh
mukesh.usts@gmail.com


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 13, 2008 3:19 pm 
Beginner
Beginner

Joined: Fri Jan 12, 2007 1:08 am
Posts: 41
I believe that you are trying to return a row count which is a different to what I was trying to illustrate above. Nevertheless this is how I would do this:

Code:
ISQLQuery sql = session.CreateSQLQuery("select count(*) column_alias from table");
sql.AddScalar("column_alias", NHibernateUtil.Int32);
int count = sql.UniqueResult<int>();


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 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.