-->
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: Is there any way to 'Fast' Delete an Entity?
PostPosted: Fri Nov 25, 2005 8:21 pm 
Newbie

Joined: Sat Jun 11, 2005 1:56 am
Posts: 19
Hi All,

I have a very slow loading Entity (has a large blob). I want to:

Code:
session.Delete("FROM EntityName WHERE EntityNameID = X");


Without it actually loading the entity first. The entity is not related to anything as is clear through the hbm.xml file. Well I know its not that clear. Here is the hbm.

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="DAL.AttachmentContent, DAL" table="`AttachmentContent`">
      <jcs-cache usage="read-write"/>      
      <id name="ID" column="`AttachmentContentID`" unsaved-value="0"><generator class="native"/></id>      
      <property name="Contents" column="`Contents`" type="Byte[](16000000)" length="16000000" not-null="true"/>
   </class>
</hibernate-mapping>


Is there anyway I can force NH to just run a delete query rather than load the entity then delete it?

Cheers

Guido Tapia

PS: Congrats on all the great news about NH lately, awesome product.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 28, 2005 3:35 pm 
Contributor
Contributor

Joined: Sat Sep 24, 2005 11:25 am
Posts: 198
I don't think so.
I thought it was stupid until I considered the case of mapped associations and cascades, that NHib needs to handle as well.
If you want to do a big delete, just write the SQL to do it.

DELETE FROM [Entity] WHERE [EntityNameID]=@id;


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 28, 2005 4:54 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 8:45 am
Posts: 226
I think this might be a handy thing to have, even if Hibernate doesn't have it. Something like:
Code:
ISession.Delete( Type type, int id );


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 28, 2005 5:21 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
that would be the same as Session.Delete(Session.Load(type, id)); would it not ? ;)

delete without handling cascades is what hibernate 3.0/3.1 has added via DML support. ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 28, 2005 7:09 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 8:45 am
Posts: 226
max wrote:
that would be the same as Session.Delete(Session.Load(type, id)); would it not ? ;)


No, the point is to delete without loading first, so it would do just that.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 29, 2005 2:30 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
so that would be:

s.createQuery("delete type where id = :id").seParameter(42).executeUpdate();

adding a delete operation on Session that does not obey delete cascade semantics doesn't sound consistent to me.

_________________
Max
Don't forget to rate


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.