2

We have Spring MVC based web-app having service method attributed with @Transactional(readonly=true).

I was expecting spring to throw exception because we have method which is committing data in mysql db.

Can anyone help me out why transaction attribute (Readonly) related exception is not thrown ?

below mentioned is code...

@Service
@Transactional
public class AppService {

... @Autowired Dao 

public int createApplication(AppVO vo){

....

}

}
user2775185
  • 1,099
  • 3
  • 17
  • 30
  • Check [this](http://stackoverflow.com/a/1712328/1777090) explanation and [this](http://stackoverflow.com/a/13884303/1777090) if helps. – MysticMagicϡ Jun 13 '14 at 05:44

1 Answers1

3

Taken straight from the Javadoc of readOnly of @Transactional is the following:

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.

So it is not unexecpected that an exception is not thrown.

geoand
  • 60,071
  • 24
  • 172
  • 190
  • Thanks. When on the service side for the experiment purpose denoting propogation value to NOT_REQUIRED, it does not throw any exception, infact it commits transaction. – user2775185 Jun 13 '14 at 06:07