开发者

EJB3 persistence with a field that's not an entity

开发者 https://www.devze.com 2023-02-04 00:52 出处:网络
I\'ve got the following situation @Entity public class myEntity implements Serializable { private AnotherClass anotherClass;

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号