-->
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.  [ 5 posts ] 
Author Message
 Post subject: session.Delete overloads - need help!
PostPosted: Sat May 21, 2005 10:19 pm 
Newbie

Joined: Sat May 21, 2005 10:16 pm
Posts: 15
Greetings,

If someone can give me examples of the three session.Delete overloads (the session.Delete(obj) I understand easy enough :-)

Delete(string query, object value, IType type)

Delete(string query)

My scenario is this - I need to delete a user and all I have is that user's unique identifier. I want to delete the user without having to load the user object.

Please advise.


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 22, 2005 5:08 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
NHibernate usually needs to load the deleted object to handle cascades and similar stuff. But if you have proxies enabled, you might get away with:
Code:
User userToDelete = session.Load(typeof(User), userId);
session.Delete(userToDelete);

But maybe Delete will still initialize the proxy, I'm not sure. Delete with the query argument executes the query, and deletes the objects returned. The value and type arguments are used to pass a parameter to the query.


Top
 Profile  
 
 Post subject: More info
PostPosted: Wed May 25, 2005 7:43 pm 
Could you provide 2 examples of using the .Delete with the query and the value and type arguments? I can not figure out the IType..


I try things such as .Delete("from assembly.Customer cst where cst._id = {0}", crit.ID, NHibernate.Type.GuidType); etc and get all sorts of errors.

I need some specific examples please.

sergey wrote:
NHibernate usually needs to load the deleted object to handle cascades and similar stuff. But if you have proxies enabled, you might get away with:
Code:
User userToDelete = session.Load(typeof(User), userId);
session.Delete(userToDelete);

But maybe Delete will still initialize the proxy, I'm not sure. Delete with the query argument executes the query, and deletes the objects returned. The value and type arguments are used to pass a parameter to the query.


Top
  
 
 Post subject:
PostPosted: Thu May 26, 2005 3:04 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Untested, but try this:
Code:
session.Delete("from assembly.Customer cst where cst._id = ?", crit.ID, NHibernateUtil.Guid)

NHibernate.Type.GuidType is a class, you need an instance, and NHibernateUtil contains static instances of all types. Also, parameters are specified using question marks.


Top
 Profile  
 
 Post subject: Thx
PostPosted: Thu May 26, 2005 1:23 pm 
Thanks much - checked the docs, looked for hibernate examples, looked at the code - could not find anything anywhere.

Your time is much appreciated - now off to test this solution out :-)


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