File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Spring and the fly likes @Transactional not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "@Transactional not working" Watch "@Transactional not working" New topic

@Transactional not working

Naresh Chaurasia
Ranch Hand

Joined: May 18, 2005
Posts: 361
I have following code:

Even thought i have set @Transactional(readOnly = true) for insert method, still the insert operation is being performed. Should not the attribute readOnly, which is set to true should take care that insert cannot be performed on this method.

SCJP 1.4, SCWCD1.4, OCA(1Z0-007)
Marshall Blythe
Ranch Hand

Joined: Feb 26, 2013
Posts: 35
According to the JavaDoc for Transactional#readOnly:

This just serves as a hint for the actual transaction subsystem; it will not necessarily cause failure of write access attempts. A transaction manager which cannot interpret the read-only hint will not throw an exception when asked for a read-only transaction.

Why is readOnly set to true on a method that performs multiple inserts? Although it causes no real harm it could be confusing for the next developer who comes along to maintain the code.
I agree. Here's the link:
subject: @Transactional not working
jQuery in Action, 3rd edition