Disabling optimistic locking for only certain properties

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Disabling optimistic locking for only certain properties

elvanor
Hi,

In Grails you can disable optimistic locking on a per class basis by using mapping {version: false}. However in Hibernate you can go further than that and disable optimistic locking only for certain attributes (properties) of a given class. In my current situation it would be really nice to have that in GORM as for some fields I don't want optimistic locking active, whereas for others it makes sense.

Is that feature already implemented in GORM? If so, how? If not, I will open a JIRA for this improvement, should not be too hard to implement with a nice DSL.

Thanks

--
Jean-Noël Rivasseau
Reply | Threaded
Open this post in threaded view
|

Re: Disabling optimistic locking for only certain properties

burtbeckwith
I've been working on adding missing stuff like that recently and hopefully it'll make it into 1.3.1. Until that's implemented you can use the approach described here: http://n4.nabble.com/GORM-setting-access-field-td1592837.html

You could check each property and exclude the ones that shouldn't be included in optimistic lock checks:

   if (property.getName().equals("foo")) {
      property.setOptimisticLocked(false);
   }

Burt

> Hi,
>
> In Grails you can disable optimistic locking on a per class basis by using
> mapping {version: false}. However in Hibernate you can go further than that
> and disable optimistic locking only for certain attributes (properties) of a
> given class. In my current situation it would be really nice to have that in
> GORM as for some fields I don't want optimistic locking active, whereas for
> others it makes sense.
>
> Is that feature already implemented in GORM? If so, how? If not, I will open
> a JIRA for this improvement, should not be too hard to implement with a nice
> DSL.
>
> Thanks
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Disabling optimistic locking for only certain properties

elvanor
Hi, thanks for the reply,

On Tue, Apr 13, 2010 at 2:24 PM, Burt Beckwith <[hidden email]> wrote:
I've been working on adding missing stuff like that recently and hopefully it'll make it into 1.3.1. Until that's implemented you can use the approach described here: http://n4.nabble.com/GORM-setting-access-field-td1592837.html

That looks a bit complex. I will wait until it's implemented - is there any JIRA I may add myself to, so that I can get notified when it's there?

 
You could check each property and exclude the ones that shouldn't be included in optimistic lock checks:

  if (property.getName().equals("foo")) {
     property.setOptimisticLocked(false);
  }

This looks like a nice workaround. That should be done in Bootstrap.groovy I guess, how do you iterate over the properties of a given class?

Jean-Noel
Reply | Threaded
Open this post in threaded view
|

Re: Disabling optimistic locking for only certain properties

burtbeckwith
There's no JIRA yet, I'm just working in a local branch. Feel free to create one, and include more than just this item - something along the lines of "Add all missing Hibernate mapping features from hbm.xml and annotations to GORM".

You need to loop through the properties while the Configuration is being built since after that it's too late and Hibernate will have cached the config, so overriding secondPassCompile() is the best place to do that.

Burt

> Hi, thanks for the reply,
>
> On Tue, Apr 13, 2010 at 2:24 PM, Burt Beckwith <[hidden email]>wrote:
>
> > I've been working on adding missing stuff like that recently and hopefully
> > it'll make it into 1.3.1. Until that's implemented you can use the approach
> > described here:
> > http://n4.nabble.com/GORM-setting-access-field-td1592837.html
> >
>
> That looks a bit complex. I will wait until it's implemented - is there any
> JIRA I may add myself to, so that I can get notified when it's there?
>
>
>
> > You could check each property and exclude the ones that shouldn't be
> > included in optimistic lock checks:
> >
> >   if (property.getName().equals("foo")) {
> >      property.setOptimisticLocked(false);
> >   }
> >
>
> This looks like a nice workaround. That should be done in Bootstrap.groovy I
> guess, how do you iterate over the properties of a given class?
>
> Jean-Noel
>


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Disabling optimistic locking for only certain properties

elvanor
Hi Burt, opened:

http://jira.codehaus.org/browse/GRAILS-6171

as per our discussion

On Wed, Apr 14, 2010 at 5:14 AM, Burt Beckwith <[hidden email]> wrote:
There's no JIRA yet, I'm just working in a local branch. Feel free to create one, and include more than just this item - something along the lines of "Add all missing Hibernate mapping features from hbm.xml and annotations to GORM".

You need to loop through the properties while the Configuration is being built since after that it's too late and Hibernate will have cached the config, so overriding secondPassCompile() is the best place to do that.

Burt

> Hi, thanks for the reply,
>
> On Tue, Apr 13, 2010 at 2:24 PM, Burt Beckwith <[hidden email]>wrote:
>
> > I've been working on adding missing stuff like that recently and hopefully
> > it'll make it into 1.3.1. Until that's implemented you can use the approach
> > described here:
> > http://n4.nabble.com/GORM-setting-access-field-td1592837.html
> >
>
> That looks a bit complex. I will wait until it's implemented - is there any
> JIRA I may add myself to, so that I can get notified when it's there?
>
>
>
> > You could check each property and exclude the ones that shouldn't be
> > included in optimistic lock checks:
> >
> >   if (property.getName().equals("foo")) {
> >      property.setOptimisticLocked(false);
> >   }
> >
>
> This looks like a nice workaround. That should be done in Bootstrap.groovy I
> guess, how do you iterate over the properties of a given class?
>
> Jean-Noel
>


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email