views:

50

answers:

2

Has anyone had any experience with Spring transactions (class-level, with proxy, annotation-driven) not getting started in a Groovy Class? I've been struggling with an unexplained LazyInitialization exception noticed that stacktrace does not include a call to start the transaction. Sounds crazy but I have to wonder whether Groovy picks up on the Transactional annotation.

A: 

If you're using Grails, you could try using

MyDomainClass.withTransaction {    
  // Code within the transaction goes here
}

as an alternative to the transactional annotation. If the code works with this approach, then you can be sure that it's the annotation that's the cause of the problem (though I understand you may not like this as a permanent solution).

Don
A: 

Actually I found the source of the problem. From the Spring documentation (i added in emphasis):

24.5.1. AOP - advising scripted beans It is possible to use the Spring AOP framework to advise scripted beans. The Spring AOP framework actually is unaware that a bean that is being advised might be a scripted bean, so all of the AOP use cases and functionality that you may be using or aim to use will work with scripted beans. There is just one (small) thing that you need to be aware of when advising scripted beans... you cannot use class-based proxies, you must use interface-based proxies. You are of course not just limited to advising scripted beans... you can also write aspects themselves in a supported dynamic language and use such beans to advise other Spring beans. This really would be an advanced use of the dynamic language support though.

My problem was that I was using class-based proxies.

algernon