public int deleteAll(final String id){
int re=0;
try{
Object i=this.getHibernateTemplate().execute(
new HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
int i=session.createQuery("update A set state='已删除' where id='"+id+"'").executeUpdate();
int j=session.createQuery("update B set state='已删除' where id='"+id+"'").executeUpdate();
int k=session.createQuery("update C set state='已删除' where id='"+id+"'").executeUpdate();
return null;
}
}
);
}catch(Exception e){
re=0;
}
return re;
}
如上程序,,,如何把里面的三个update语句处在同一事务中 ???
急............
你要这样的?
[code="java"] Transaction tx = null;
try
{
tx = session.beginTransaction();
int i=session.createQuery("update A set state='已删除' where id='"+id+"'").executeUpdate();
int j=session.createQuery("update B set state='已删除' where id='"+id+"'").executeUpdate();
int k=session.createQuery("update C set state='已删除' where id='"+id+"'").executeUpdate();
tx.commit();
}
catch (HibernateException he)
{
tx.rollback();
throw he;
}
finally
{
}[/code]
或者这样的在Spring里配置的?
[code="xml"]
PROPAGATION_REQUIRED
PROPAGATION_REQUIRED
PROPAGATION_REQUIRED
PROPAGATION_REQUIRED
PROPAGATION_REQUIRED,readOnly
[/code]