Hibernate 使用 ehcache 缓存,many-to-one 中的one为空

J2EE 码拜 9年前 (2015-04-02) 1088次浏览 0个评论

在使用Hibernate4,ehcache 2.6时,对实体类进行缓存, 
实体类配置如下: 
   <class name=”com.test.model.Info” table=”info”> 
          <cache usage=”read-write”/> 

many-to-one 配置: 

<many-to-one name=”type” class=”com.test.model.Type” 
column=”type_id” lazy=”false” insert=”false” update=”false” not-found=”ignore”/> 

ehcache.xml配置如下: 
<cache name=”com.test.model.Info” maxEntriesLocalHeap=”100″ 
eternal=”false” timeToIdleSeconds=”300″ timeToLiveSeconds=”600″ overflowToDisk=”false” /> 

在列表页读取One中的数据,对新添加的Info,第二次刷新列表,One的属性为Null。 

是哪里不对吗?

Hibernate 使用 ehcache 缓存,many-to-one 中的one为空
20分
many to one里加上outer-join=”true” 看看
Hibernate 使用 ehcache 缓存,many-to-one 中的one为空
加上outer-join=”true” 还是不行,
我纳闷的是,在我重启Tomcat之后,直接点列表,one是有数据的,我在many那边新加一条记录,返回到列表,这时新加的那条one也是有数据,此时刷新一下列表后,新加的那条的one已经为null了,而其他原来的数据还是有的,不解。
Hibernate 使用 ehcache 缓存,many-to-one 中的one为空
20分
刷新是不是又提交了一次?
Hibernate 使用 ehcache 缓存,many-to-one 中的one为空
刷新是使用list()方法又重新取了一次,不是重新提交。
Hibernate 使用 ehcache 缓存,many-to-one 中的one为空
20分
引用 5 楼 xiaojiit 的回复:

刷新是使用list()方法又重新取了一次,不是重新提交。

你看一下 数据库 many提交完,one那边数据库是否真的入库? 还是走的数据库缓存并未实际意义提交。

Hibernate 使用 ehcache 缓存,many-to-one 中的one为空
20分
如果光走的list   怀疑是事务导致了数据回滚
Hibernate 使用 ehcache 缓存,many-to-one 中的one为空
没有走缓存,确实到数据库里了。我是直接save(many) 这样保存,保存Many,不会修改one的。
Hibernate 使用 ehcache 缓存,many-to-one 中的one为空
楼主我遇到了相同问题,many to one one中的缓存好像加载不到many中,楼主你如何解决的

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明Hibernate 使用 ehcache 缓存,many-to-one 中的one为空
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!