-->
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.  [ 6 posts ] 
Author Message
 Post subject: Delete Query with CreateSQLQuery
PostPosted: Sun Aug 05, 2007 10:11 am 
Newbie

Joined: Wed Sep 27, 2006 2:54 pm
Posts: 15
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 1.2.0.4000

The generated SQL (show_sql=true): true

hi,
as i always used SQL queries for my delete , now i found that i can do it with nHibernate 1.2.0 with CreateSQLQuery() .
there are 2 problem in using it ?
1. is it just for select ? because if i want to use it for Delete it makes me to AddEntity for ResultType ! Although delete query have not any result !!

2. is there any point that i should be aware in using it ? can i use it for all SQL queries (Select/Insert/Update/Delete/....) ?

thanks a lot.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 06, 2007 4:53 am 
Newbie

Joined: Wed Sep 27, 2006 2:54 pm
Posts: 15
is there anybody out there can help/Answer me ????


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 08, 2007 5:34 am 
Newbie

Joined: Wed Sep 27, 2006 2:54 pm
Posts: 15
No Support for NHibernate !!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 09, 2007 10:55 am 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
Sorry it took so long for you to get an answer, but it is usually the case that you're less likely to get an answer when something isn't supported, because most folks (even the experienced ones) can't be sure that even non-standard uses of NH don't have some form of workaround or useful hack.

At any rate, it makes sense that this wouldn't be supported. The whole purpose for SQLQuery is to allow NH to build objects from SQL rather than HQL. If you have to do something else with SQL (C/U/D in bulk), there are other mechanisms for doing so (ADO.NET). These need not be kept strictly separate from NH, either. You can use the same connection for your DELETE, even include it in an NH transaction using ITransaction.Enlist().

I guess the question is, why did you need CreateSQLQuery to build a delete query?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 13, 2007 8:13 am 
Newbie

Joined: Wed Sep 27, 2006 2:54 pm
Posts: 15
thanks for your reply,

as i am using it with SQLITE and when nhibernate start a transaction, the SQLITE file been locked , and i cannot do any other things on it.
i am in a situation that i need to do some delete with Nhibernate and some delete via native SQL DELETE command , so i should do NHibernate delete first and then do other deletes, and in any case that one of them throws exception i need to rollback all. so if nhibernate can run a SQL Query for me (through all its resources) i can do it without 2 transaction and just with 1.

maybe it is a suggestion or Request for next version of NHibernate , if it can run just a SQL Query (S/U/D etc) via it's connection or it's resources.

and in this case , all the Database related works , goes through the NHibernate and NHibernate will be really an intermediate between Logic Layer and DataBase Layer.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 14, 2007 12:23 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
tiva, as I wrote, the behavior you need is indeed possible with NH currently and you are confused about the reason for the existence of SQLQuery. I'll leave disabuse to the latter to your own study. To illustrate the former more specifically, here's how to do what you want in pseudocode:

Code:
using ( ISession sess = factory.OpenSession() )
using ( ITransaction tx = sess.BeginTransaction() ) {
   // do some NH CRUD...

   // perform bulk delete in the same transaction!
   IDbCommand deletecommand = sess.Connection.CreateCommand();
   deletecommand.CommandText = "...";
   // other command formatting

   tx.Enlist( deletecommand );
   deletecommand.ExecuteNonQuery();

   //do some more NH or bulk stuff
   .
   .
   .

   // oops!?
   if ( oops ) {
      tx.Rollback();
      return;
   }

   // done!
   tx.Commit();
}


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