Can't Serialize Session Beans - Warning thrown

◇◆丶佛笑我妖孽 提交于 2019-12-02 08:59:59

Making a class Serializable does not means everything in it will be serializable. All references(dependencies/properties) in your class, they themselves should be serializable and in turn their references.

As per above exception it seems your session bean is having reference to EntityManagerFactoryImpl object which is not serializable and hence the error.

To solve this you can define it as transient than it wont be serialized but only problem will be during de-serialization you will have to build the object or assign reference manually.

I suggest have a look at this article on Serilization.

How to solve this, I don't do JPA so cannot tell if there is some serialized class for same,

To solve it define the reference as transient

transient EntityManagerFactory entityManagerFactory

and assign the reference back to bean manually in deserialization hook method as described below.

private void readObject(java.io.ObjectInputStream stream)
        throws java.io.IOException, ClassNotFoundException
    {
        stream.defaultReadObject();

        // assign reference manually.
        this.entityManagerFactory =  //get from factory;
    }

Hope this helps !!!!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!