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