Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

handling hibernate UnsupportedOperationException: Can't write to a readonly object

Tags:

java

hibernate

What configuration parameters or session preferences do I need to set to fix this? Can't write to a readonly object? Here is the stacktrace for more information:

Caused by: java.lang.UnsupportedOperationException: Can't write to a readonly object
        at org.hibernate.cache.ReadOnlyCache.lock(ReadOnlyCache.java:43)
        at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:85)
        at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
        at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
        at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
        at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
        at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
        at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
        at com.mycompany.arch.submission.registry.bean.RegSubmissionSpringService.perform_flush(RegSubmissionSpringService.java:1108)
        at com.mycompany.arch.submission.registry.bean.RegSubmissionSpringService.saveRegistryData(RegSubmissionSpringService.java:1062)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
        at $Proxy145.saveRegistryData(Unknown Source)
        at com.mycompany.arch.submission.registry.bean.RegDataAccessManager.persistRegistry(RegDataAccessManager.java:54)
like image 992
Laxmikanth Samudrala Avatar asked Feb 19 '10 20:02

Laxmikanth Samudrala


2 Answers

For the lazy/stupid people amongst us (like me ;))

changing

@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)

into

@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)

(for example)

(in the database type pojo)

might help too :)

S.

like image 175
MadBoomy Avatar answered Oct 16 '22 01:10

MadBoomy


See if this blog page is useful:

Check that your Hibernate class mapping has mutable="false", which prevents Hibernate from issuing updates for already existing instances. Here is a link to my Hibernate Forums thread about this problem.

like image 31
Kevin Avatar answered Oct 16 '22 03:10

Kevin