嘗試使用FlexJSON序列化JPA/Hibernate實體時出現了一個非常奇怪的錯誤。對象本身不是什麼幻想;只是字段和其他對象之間的關係。Hibernate和FlexJSON的懶惰初始化錯誤
Caused by: flexjson.JSONException: Error trying to deepSerialize
at flexjson.transformer.ObjectTransformer.transform(ObjectTransformer.java:61)
at flexjson.transformer.TransformerWrapper.transform(TransformerWrapper.java:22)
at flexjson.transformer.ObjectTransformer.transform(ObjectTransformer.java:49)
at flexjson.transformer.TransformerWrapper.transform(TransformerWrapper.java:22)
at flexjson.transformer.ObjectTransformer.transform(ObjectTransformer.java:49)
at flexjson.transformer.TransformerWrapper.transform(TransformerWrapper.java:22)
at flexjson.transformer.ObjectTransformer.transform(ObjectTransformer.java:49)
at flexjson.transformer.TransformerWrapper.transform(TransformerWrapper.java:22)
at flexjson.JSONContext.transform(JSONContext.java:73)
at flexjson.JSONSerializer.serialize(JSONSerializer.java:377)
at flexjson.JSONSerializer.serialize(JSONSerializer.java:235)
Caused by: java.lang.reflect.InvocationTargetException
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:597)
at flexjson.BeanProperty.getValue(BeanProperty.java:102)
at flexjson.transformer.ObjectTransformer.transform(ObjectTransformer.java:37)
... 89 more
Caused by: java.lang.IllegalStateException: Cannot call isReadOnlyBeforeAttachedToSession when isReadOnlySettingAvailable == true
at org.hibernate.proxy.AbstractLazyInitializer.isReadOnlyBeforeAttachedToSession(AbstractLazyInitializer.java:308
從閱讀其他(稀疏)的帖子,看看代碼看起來像這是一個懶惰的初始化問題。這種情況在很少的情況下反覆發生,但這些情況是可重複的。我的猜測是,因爲它似乎是有狀態的,它與數據有關,但我真的不知道爲什麼數據會導致這種異常,尤其是因爲它非常罕見。
我們應該如何去雖然不序列化延遲加載屬性? – chrismarx