GeeCON Prague 2014*
The moose likes Spring and the fly likes Exception on Save operation with Spring annotation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Exception on Save operation with Spring annotation" Watch "Exception on Save operation with Spring annotation" New topic
Author

Exception on Save operation with Spring annotation

Rendi Artha
Greenhorn

Joined: Jan 20, 2010
Posts: 29
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

Joined: Feb 09, 2010
Posts: 4
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

Joined: Jan 20, 2010
Posts: 29
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 :

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception on Save operation with Spring annotation