处理hibernate UnsupportedOperationException:无法写入只读对象

时间:2010-02-19 20:02:53

标签: java hibernate

我需要设置哪些配置参数或会话首选项才能解决此问题?无法写入只读对象?以下是stacktrace以获取更多信息:

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)

2 个答案:

答案 0 :(得分:8)

查看此blog page是否有用:

  

检查你的Hibernate类   mapping有mutable =“false”,其中   阻止Hibernate发布   现有的更新   实例。这是我的链接   Hibernate论坛关于此问题   问题

答案 1 :(得分:4)

对于我们中间的懒惰/愚蠢的人(像我一样;))

改变

@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)

@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)

(例如)

(在数据库类型pojo中)

也可能有所帮助:)

S上。