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 to override the categories view page in cs cart?

php cs-cart

I have a new addon named drill_search and I need to display a message on the category view page's view.tpl How can I achieve this?

check polygon features in boost

c++ boost

I recently tried to work on boost::geometry library. I found the code below

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.