Grails

Methods in domain-classes and TagLibs are not transactional by default

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Won't Fix
  • Affects Version/s: 1.2 final
  • Fix Version/s: 1.2.1
  • Component/s: Persistence, TagLib
  • Labels:
    None

Description

In my domain class I have a method like:

def vicinity( params ){
DomainClazz.executeQuery( "select a, sqrt(...) from ....", params ).collect{ e -> e[ 0 ].mainParent.name // << here the LIE is thrown! e[ 0 ] }
}

Sometimes, the lazy-init-exc is thrown, meaning, that only executeQuery() runs in it's own TX, but not collect() closure and the whole method.

The same goes also for TagLibs

Activity

Hide
Jeff Brown added a comment -

Taglibs and domain class methods are not supposed to be transactional by default.

Show
Jeff Brown added a comment - Taglibs and domain class methods are not supposed to be transactional by default.
Hide
Konstantyn Smirnov added a comment - - edited

well, about Taglibs it's arguable indeed, but the domain-classes are persistant objects so, all methods shall be also persisting, i.e. transactional.
It doesn't look very consistent, if all methods that get injected by GORM and not defined in a class itself ARE transactional, but class's own methods ARE NOT.

Show
Konstantyn Smirnov added a comment - - edited well, about Taglibs it's arguable indeed, but the domain-classes are persistant objects so, all methods shall be also persisting, i.e. transactional. It doesn't look very consistent, if all methods that get injected by GORM and not defined in a class itself ARE transactional, but class's own methods ARE NOT.
Hide
Graeme Rocher added a comment -

This is by design. onl services use transactional proxies for demarcation. If you want a transaction in a domain method use Domain.withTransaction or do you operations in a service. Introducing proxies around domain instances for this case will produce unwanted side effects. Please do not re-open issues if they are be closed without providing proper justification and agreement to re-open.

Show
Graeme Rocher added a comment - This is by design. onl services use transactional proxies for demarcation. If you want a transaction in a domain method use Domain.withTransaction or do you operations in a service. Introducing proxies around domain instances for this case will produce unwanted side effects. Please do not re-open issues if they are be closed without providing proper justification and agreement to re-open.
Hide
Konstantyn Smirnov added a comment -

errm...

Correct me if I'm wrong, but the injected GORM-methods introduce the proxy around the domain instance already. It wouldn't be really difficuilt to add some TX-stuff around the declared methods...
At best would it be to have a possibility to choose, whether to make domain classes transactional.

Show
Konstantyn Smirnov added a comment - errm... Correct me if I'm wrong, but the injected GORM-methods introduce the proxy around the domain instance already. It wouldn't be really difficuilt to add some TX-stuff around the declared methods... At best would it be to have a possibility to choose, whether to make domain classes transactional.
Hide
Graeme Rocher added a comment -

There is no proxy added to inject GORM methods. Since proxies result in read issues when dealing with object equality and Hibernate already uses proxies to do lazy loading introducing another layer of proxying would cause many breakages and awkward side effects

Show
Graeme Rocher added a comment - There is no proxy added to inject GORM methods. Since proxies result in read issues when dealing with object equality and Hibernate already uses proxies to do lazy loading introducing another layer of proxying would cause many breakages and awkward side effects
Hide
Jeff Brown added a comment -

GORM methods are added using Groovy metaprogramming, not Spring proxies.

Show
Jeff Brown added a comment - GORM methods are added using Groovy metaprogramming, not Spring proxies.

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: