我有以下模型类:
@Entity
public class A {
private B b;
}
@Embeddable
public class B {
...
} 我使用的是Spring MVC,控制器用@Transactional注解,并且指定了以下datanucleus属性(以及其他属性)
datanucleus.detachAllOnCommit=true
datanucleus.detachAllOnClose=true
datanucleus.detachState=all
datanucleus.copyOnAttach=true
datanucleus.attachSameDatastore=true
datanucleus.maxFetchDepth=2在视图(JSP)中,当事务应该结束并且对象分离时,如果我试图访问${a.b.whatever},我会得到这个错误
javax.jdo.JDODetachedFieldAccessException: You have just attempted to access field "b" yet this field was not detached when you detached the object. Either dont access this field, or detach it when detaching the object.
A.jdoGetb(A.java)
A.getB(A.java)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
javax.el.BeanELResolver.getValue(BeanELResolver.java:62)
javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
org.apache.el.parser.AstValue.getValue(AstValue.java:123)
org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:935)..。
我使用的是带有MySQL的DataNucleus 3.1.3。
你知道为什么会这样吗?我怎么才能修复它?
发布于 2013-02-28 20:08:56
添加
@Basic(fetch=FetchType.EAGER)在此之前
private B b;这将使B急切地被获取,并使其可适当地分离。
https://stackoverflow.com/questions/15132282
复制相似问题