我遇到以下情况
@Entity
public class myEntity implements Serializable {
private AnotherClass anotherClass;
}
public class AnotherClass implements Serializable {
private String ...
private String ...
}
但是 AnotherClass
没有用 @Entity
注释。我可以成功部署我的 bean,但是当我尝试保留 MyEntity
类实例时,它给出了 NoSerializedException
。
这是因为AnotherClass
没有用@Entity
注释吗?
最佳答案
本质上是的,尽管这里还发生了其他事情。
由于 AnotherClass
既不是 @Entity
也不是 @Embeddable
,JPA 可能会尝试将其序列化为二进制字段。它似乎正在尝试这样做,但 NotSerializedException
表明 MyEntity
或 AnotherClass
的某些其他字段不是 可序列化,导致异常。
您几乎肯定不希望 AnotherClass
作为二进制文件保留,因此您需要对其进行注释以告诉 JPA 如何保留它。
关于java - EJB3 持久化非实体字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4690917/