I've got the following situation
@Entity
public class myEntity implements Serializable {
private AnotherClass anotherClass;
}
public class AnotherClass implements Seria开发者_运维百科lizable {
private String ...
private String ...
}
but AnotherClass
IS NOT annotated with @Entity
. I can successfully deploy my bean but when I try to persist a MyEntity
class instance, it gives me NoSerializableException
.
Is this because AnotherClass
is not annotated with @Entity
?
Essentially, yes, although there's something else going on here.
Since AnotherClass
is neither @Entity
or @Embeddable
, JPA may try to serialize it as a binary field instead. It seems to be trying this, but the NotSerializableException
suggests that some other field of either MyEntity
or AnotherClass
isn't serializable, causing the exception.
You almost certainly don't want AnotherClass
persisted as a binary, so you need to annotate it to tell JPA how to persist it.
精彩评论