• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception on Save operation with Spring annotation

 
Rendi Artha
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found exception as below
org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.


here my code :
applicationContext.xml



ItemManager.java



The exception occures only on save operation, it wont happens on another operation.
Any hints or suggestion would be appreciate.

Thanks.
Rendi (A.K.A CriterionNewbi)
 
Henry Mbadiwe
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is that you defined your transactional annotation in the interface instead of the implementation.
These annotations aren't inherited by your implementing class.

The above should be defined in your implementation.
 
Rendi Artha
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This weird situation is caused by OpenSessionInViewFilter.
Check this link Exception reason

as Juergen Hoeller said

Invoking HibernateTemplate's save/update/delete methods on a Spring-managed Session in FlushMode.NEVER is potentially dangerous: It means that you are:

* either doing this in a Spring-managed read-only transaction, which will never flush the Hibernate Session, i.e. never flush your save/update/delete calls. The new check makes you aware that you won't persist your changes in that situation.

* or working with some other thread-bound Session in FlushMode.NEVER, for example the OpenSessionInViewFilter. If you're overriding closeSession there to flush after view rendering, you should override getSession too, setting the Session to FlushMode.AUTO.


so i create another filter to force that FlushMode is AUTO/COMMIT

here my code :



and I change web.xml configuration as below :

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic