尝试使用 FlexJSON 序列化 JPA/Hibernate 实体时遇到一个非常奇怪的错误。对象本身并不花哨;只是其他对象之间的字段和关系。
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
通过阅读其他(稀疏)帖子并查看代码,这似乎是延迟初始化的问题。这种情况在极少数情况下会重复发生,但这些情况是可重复的。我的猜测是因为它似乎是有状态的,它与数据有关,但我真的不知道为什么数据会导致这种异常,特别是因为它是如此罕见。