0

I get the following exception when I upgrade my app from Hibernate 3.0.5 with Spring 1.0 to Hibernate 4.3.5.Final with Spring 4.0.6.

Caused by: org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.
  at org.springframework.orm.hibernate4.HibernateTemplate.checkWriteOperationAllowed(HibernateTemplate.java:1135)
  at org.springframework.orm.hibernate4.HibernateTemplate$26.doInHibernate(HibernateTemplate.java:826)
  at org.springframework.orm.hibernate4.HibernateTemplate.doExecute(HibernateTemplate.java:340)
  at org.springframework.orm.hibernate4.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:308)
  at org.springframework.orm.hibernate4.HibernateTemplate.deleteAll(HibernateTemplate.java:823)
  ... 

I have spent several days, done some reasearch, tried different things, and asked the question below: How can I globally set FlushMode for Hibernate 4.3.5.Final with Spring 4.0.6?

Seems like there are 2 solotions I can go with, but I have still not found the recommended approach.

Approach 1:

Implement a custom version of OpenSessionInViewFilter to set the default FlushMode to AUTO.

Approach 2:

Use a TransactionManager, and add the @Transactional annotation to every method that has write access to the database. This can be done by following: Spring Hibernate transaction management


Could anyone provide any suggestion, or point out any documentation related to "Starting from version x.x.x, this is how we should implement Hibernate now!"

Thanks a lot

Community
  • 1
  • 1
Max
  • 1,064
  • 9
  • 23
  • 1
    http://stackoverflow.com/a/23879413/2231632 ? – Praba Sep 08 '14 at 13:29
  • @prabugp Thanks a lot. Although it's not an official solution, the comment provided by 'Fernando Rincon' on the other post makes a lot of sense! – Max Sep 08 '14 at 15:52
  • Great! If you solved it, please mark this question as answered. – Praba Sep 08 '14 at 15:54
  • @prabugp Thanks but I don't think a comment can be marked as answered. Also, I'm still expecting an official answer. I'm planning on finding out the first version of Hibernate that introduces FlushMode.MANUAL, and check the release note for suggestions. – Max Sep 09 '14 at 08:26

0 Answers0