1

次のモデル クラスがあります。

@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 を使用しています。

なぜこれを修正できますか?

4

1 に答える 1

1

Add

 @Basic(fetch=FetchType.EAGER)

before

private B b;

This will make B eagerly fetched and make it properly detachable.

You can experiment with fetch groups to specify what should be fetched when.

于 2013-02-28T12:08:56.137 に答える