Spring - inner methods called by @Transactional(readOnly = true) method to write

If a method has annotation @Transactional(readOnly = true), is there a way to allow inner methods to write?


Class A {
   @Transactional(readOnly = true) 
   public void readFoo(){

Class B {
   public void writeFoo(){}

I know it sort of defeats the purpose of having the readOnly annotation but I just want to know if there's a way.


readOnly attribute of @Transaction annotation is just hint for the transaction manager. It depends on underlying technology you use to manage transactions. It can just optimize transactions read-only performance (Hibernate) or it can simply ignore readOnly attribute at all.

I think that if you annotate writeFoo() i.e. like this

@Transactional(readOnly = false, propagation = Propagation.NESTED)

It can act independently on parent read-only transaction and write without problems. But I haven't tested this myself.

@Transactional(propagation = Propagation.REQUIRES_NEW) worked for me. A thing to be cautious about is that if the method takes in a hibernated object, this will not work. This only works if you retrieve the hibernated object and makes changes within the Propagation.REQUIRES_NEW method.

Need Your Help

How would you design a docking library for WPF?

wpf design-patterns oop docking

I want to implement a docking library in wpf with behavior similar to Adobe Photoshops CS3.

Injecting & Configuring Gradle Builds

java groovy build gradle

I'm reading up on Gradle and am very interested in it, specifically because (it appears) that it allows the introduction of inheritance into the build process. For instance, if I have a Java web ap...

Evaluating string “3*(4+2)” yield int 18

c# string math numeric evaluate

Is there a function the .NET framework that can evaluate a numeric expression contained in a string and return the result? F.e.:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.