请教Ehcache结合spring ,hibernate的问题

@Cacheable(modelId = "cache")
public User detail(String id) {
return getSession().get(User.class, id);
}

报org.springmodules.cache.provider.ObjectCannotBeCachedException: The cache can only store implementations of java.io.Serializable

错误

如果改成:

@Cacheable(modelId = "cache")
public User detail(String id) {
return getSession().load(User.class, id);
}

就不报错 ,这是为什么呢

Session.load/get方法均可以根据指定的实体类和id从数据库读取记录,并返回与之对应的实体对象。其区别在于:

如果未能发现符合条件的记录,get方法返回null,而load方法会抛出一个ObjectNotFoundException。
load()方法可返回实体的代理类实例,而get方法永远直接返回实体类。
load方法可以充分利用内部缓存和二级缓存中的现有数据,而get方法则仅仅在内部缓存中进行数据查找,如没有发现对应数据,将越过二级缓存,直接调用SQL完成数据读取。