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.  [ 2 posts ] 
Author Message
 Post subject: Bulk Update and Delete
PostPosted: Wed Mar 12, 2008 9:44 am 
Newbie

Joined: Mon Sep 10, 2007 10:01 am
Posts: 2
I've been thinking about how NHibernate doesn't yet easily support bulk operations on entities and I think this is something that many of us could really use.

This might not be the correct forum, but I wanted to propose some ideas to maybe get people thinking about this and hopefully inspire us to patch or provide extension points to support this.

Right now, we have DetachedCriteria which gives us a rich API we can use to describe the WHERE clause of a SELECT.

We could leverage that existing logic to drive the WHERE clauses of DELETES and UPDATES.

For example:

Code:
DeleteCriteria delete = DeleteCriteria.For(typeof(SomeEntity))      // DELETE FROM SomeEntity s
    .Add(Expression.Eq("SomeProperty", someValue));                 // WHERE s.SomeProperty = someValue


UpdateCriteria update = UpdateCriteria.For(typeof(SomeEntity))      // UPDATE SomeEntity s
    .Add(Update.SetProperty("PropertyName", newValue))              // SET s.PropertyName = newValue
    .Add(Update.CopyProperty("Destination", "Source"))              // ,s.Destination = s.Source
    .Add(Update.Numeric("NumericProperty", n, Numeric.Add)          // ,s.NumericProperty = s.NumericProperty + n
    .Add(Update.Numeric("NumericProperty", n, Numeric.Subtract)     // ,s.NumericProperty = s.NumericProperty - n
    .Add(Update.Numeric("NumericProperty", n, Numeric.Multiply)     // ,s.NumericProperty = s.NumericProperty * n
    .Add(Update.Numeric("NumericProperty", n, Numeric.Divide)       // ,s.NumericProperty = s.NumericProperty / n
    .Add(Update.Numeric("Numeric1", "Numeric2", Numeric.Add)        // ,s.Numeric1 = s.Numeric1 + s.Numeric2
    .Add(Update.Numeric("Numeric1", "Numeric2", Numeric.Subtract)   // ,s.Numeric1 = s.Numeric1 - s.Numeric2
    .Add(Update.Numeric("Numeric1", "Numeric2", Numeric.Multiply)   // ,s.Numeric1 = s.Numeric1 * s.Numeric2
    .Add(Update.Numeric("Numeric1", "Numeric2", Numeric.Divide)     // ,s.Numeric1 = s.Numeric1 / s.Numeric2
    .Add(Expression.Eq("SomeProperty", someValue));                 // WHERE s.SomeProperty = someValue


I really don't want to have to write SQL to do these types of things when NHibernate already has knowledge about my model.

Does anyone else think this is worthwhile? What other things can we add to this? How do we go about working on this if it is worthwhile?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 12, 2008 10:40 am 
Regular
Regular

Joined: Wed Jan 25, 2006 1:11 am
Posts: 118
Location: Copenhagen, Denmark
Java Hibernate already has this in HQL and there is a JIRA entry about it in nHibernate. But i think its a great idea to consider this in Criteria API too (which i don't think Hibernate has)


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