休眠会话无法在创建的下一个(新)会话中读取更新的数据 [英] hibernate session not reading updated data in next(new) session created

查看:50
本文介绍了休眠会话无法在创建的下一个(新)会话中读取更新的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Web应用程序中使用Hibernate和spring.在一种形式上提交,我将一些数据保存在表格中.处理提交的同一个控制器会将页面重定向到另一种形式.即到另一个表单控制器.此表单必须使用一些数据,具体取决于打开前最后提交的数据.我创建一个新的休眠会话以获取数据.

I am using Hibernate and spring in my web-app. On one forms submit i save some data in a table. the same controller that handles the submit redirects the page to another form. i.e. to another form controller. this form must use some data depending on the data submitted in last form before opening.i create a new hibernate session to fetch data.

,但是由于某种原因,它不能从表中读取更新的数据(它读取旧数据). 我确保提交事务(它确实保存了我已在数据库中检查的数据.)我还确保关闭会话.

but for some reason it is not able to read updated data from the table( it reads old data). I have make sure to commit the transaction (It do save data i have checked in data base.) I also made sure to close session.

我为每个请求创建一个新会话,然后关闭该会话,然后再返回查看.

I create a new session for each request and close this session, before moving back to view.

为什么休眠无法读取新数据?

Why hibernate is not able to read new data?

推荐答案

最初,我相信它的缓存问题,但是由于第二级缓存未应用并且会话是新形式的新会话,因此第一级缓存也不是问题.

Initially i believed its cache problem but since second level cache is not applied and session is new in new form so first level cache is also not a problem.

问题究竟是什么仍然是个谜,但我得到了解决方法

what exactly is the problem is still a mystery but i got a work-around

我在配置中添加了以下属性,值为2

i added following property in my configuration with value 2

"hibernate.connection.isolation"

"hibernate.connection.isolation"

它解决了我的问题.但是欢迎您提供更多详细信息,因为我不清楚这是什么.

It fixed my problem. but More details about it is welcome as I am not clear what is this about.

这篇关于休眠会话无法在创建的下一个(新)会话中读取更新的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆