我们项目用的spring2+hibernate3
然后在代码里我用getHibernateTemplate().save(object)方法保存一个对象,接着再改变这个object里的值再getHibernateTemplate().update的时候 报错了,是这个object不再在session里了。事物是spring管理的。
请问下怎么能让这个object继续保存在session里呢?
然后在代码里我用getHibernateTemplate().save(object)方法保存一个对象,接着再改变这个object里的值再getHibernateTemplate().update的时候 报错了,是这个object不再在session里了。事物是spring管理的。
请问下怎么能让这个object继续保存在session里呢?
解决方案 »
- mysql load文件合法性判断
- JSF复选框分行的问题
- Struts上传问题,请高手帮忙,谢谢!
- 在javascript函数中怎么写servlet的路径??
- 做不下去了!!如何把RESULTSET 的数据插入或者更新到另外一个库的表中。
- struts2 的convention插件问题
- 启动Tomcat5的时候,为什么有时候有一大串错误信息,但是关闭后接着启动错误又没有,何解?
- 简直让我愤怒,解析xml时出现异常,直接找不到北了!诸位英雄,救命!
- 急 jdk在linux上的安装
- SpringMVC 使用@RequestBody 返回 400
- 如何解决java.lang.NullPointerException
- struts2问题???
hibernate的Object一直保存着的,除非你session.clear()获得evit(object);
org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException: Object of class [com.ccit.csw.t2.model.NcsRealprocT2cwopenRecorde] with identifier [100000091]: optimistic locking failed; nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.ccit.csw.t2.model.NcsRealprocT2cwopenRecorde#100000091]
Caused by:
org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.ccit.csw.t2.model.NcsRealprocT2cwopenRecorde#100000091]
getHibernateTemplate().saveOrUpdate(transientInstance);
}
public void update(NcsRealprocT2cwopenRecorde transientInstance) throws BaseException {
//getHibernateTemplate().load(transientInstance,transientInstance.getT2cwRecordeId());
//updateEntity(transientInstance);
getHibernateTemplate().saveOrUpdate(transientInstance);
}=============================================
action里的代码:
comboT2Service.insertRecord(recordVo);
//中间有些改变 recordVo 的值的代码
//更新数据
comboT2Service.updateRecord_NumHandle(recordVo, baseVo);
==============================================
上面两个方法都是在服务层里定义的,实现就是直接调上面DAO里的方法
<bean id="transactionInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<!-- 事务拦截器bean需要依赖注入一个事务管理器 -->
<property name="transactionManager" ref="transactionManager" />
<property name="transactionAttributes">
<!-- 下面定义事务传播属性 -->
<props>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
就这么一段,我不懂,是别人配的
<!-- 配置事务管理器,使用Hibernate局部事务管理器策略 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
类配置进去?什么意思?现在就是数据保存进去了,如果在update方法前加一句load的时候就可以更新到数据了。所以我怀疑是save后对象编程临时的了,你说的svae没有提交也有可能。不过没提交为什么数据库里有数据?