4

Please help- My application was working fine until today. Today I got the exception "could not deserialize". java.io.eofException. And sometimes I was able to get the data. The problem was intermittent. What could be the issue here?

@Entity
@Cacheable
@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
public class Filter {
private int id;
    private String name;
    private User user;
    private NameValue[][] filterMap;


    @Id
    @GeneratedValue(strategy=GenerationType.SEQUENCE)
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }

    @ManyToOne(
            targetEntity = User.class
    )
    @JoinColumn(name="userName")
    public User getUser() {
        return user;
    }
    public void setUser(User user) {
        this.user = user;
    }
    @Lob
        public NameValue[][] getFilterMap() {
        return filterMap;
    }
    public void setFilterMap(NameValue[][] filterMap) {
        this.filterMap = filterMap;
    }
1
  • Can you provide more details? Probably stack trace
    – Anshu
    Commented Oct 15, 2012 at 17:53

3 Answers 3

6

This probably happens because the object can be cached, and you must have configured the cache to overflow to disk (or any other storage).

The problem happens when you try to serialize or deserialize the class, and one or more of the following happen:

  1. The class or any of the fields (such as User) don't implement Serializable
  2. The class has changed since the last deploy and java generates a new serialVersionUID. When java tries to load an object that was previously on the disk cache, the serialVersionUID don't match and the error is thrown.
  3. You're using a different JVM which generates a different serialVersionUID
2
  • Hi Augusto! Thanks a lot for your reply. Actually I am using ha-jdbc as well. And we have our L2 cache enabled in the production <property name="cache.use_second_level_cache">true</property> <property name="hibernate.cache.region.factory_class"> org.hibernate.cache.infinispan.InfinispanRegionFactory</property> <property name="cache.use_query_cache">false</property> I don't completely understand the cache usage. But maybe I will try disabling it.
    – Jess
    Commented Oct 15, 2012 at 18:06
  • Hi Jess, try making the hiberate classes Serializable, that might fix the issue.
    – Augusto
    Commented Oct 15, 2012 at 20:20
1

You have to implement Serializable interface for Hibernate entity and keep default private static final long serialVersionUID = 1L. Its value can be anything, not necessarily 1L only.

eg:

public class Med implements Serializable {
   private static final long serialVersionUID = 1L;
}
0

This issue i faced and got solution , for me it's resolved db side manually inserted some rows after rest of the rows inserted Hibernate so while retrieving time this error raised solution is simple remove db data entire or manually entered rows freshly insert through hibernate after then retrieve data(criteria) this time no exception. - Mallikarjun Chinta

Not the answer you're looking for? Browse other questions tagged or ask your own question.