抱歉,我在问这个常见问题 当两个Web服务调用相同的方法并且每次调用方法isUserValid()时,我都会遇到异常。用户验证返回true但仍然获得异常。为什么只有在第二次调用它才会抛出异常,我在第一次结束之前调用第二个Web服务。 有没有办法让两个人分别调用执行。
org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.dmainc.commons.security.User#4]
问题方法 -
public UpdateFileRequest getUpdateFragment(UpdateFilter filter)
{
Session session = null;
Transaction transaction = null;
UpdateFileRequest request = new UpdateFileRequest();
UpdateFragmentReleaseFilter releaseFilter = null;
try
{
session = HibernateUtils.currentSession();
transaction = session.beginTransaction();
releaseFilter = new UpdateFragmentReleaseFilter(filter);
// are the user credentials valid
if(ServiceUtils.isUserValid(releaseFilter))
{
//Getting exception at this place while committing the transacation
HibernateUtils.commit(transaction);
}
currentSession方法
public static Session currentSession() throws HibernateException {
Session s = session.get();
if(s != null)
s = validateSession(s);
// Open a new Session, if this Thread has none yet
if (s == null) {
if (log.isDebugEnabled())
log.debug("Opening new session");
s = session_factory.openSession();
session.set(s);
new_session.set(Boolean.TRUE);
} else if (!isNewSession()) {
new_session.set(Boolean.FALSE);
}
return s;
}
答案 0 :(得分:0)
我已经能够通过在每个Web服务调用上创建新会话来解决问题,尽管使用正在进行的会话。