spring中,如何判断hibernate事务是否成功
巫医风子 2008-11-09 08:52:56 我是使用spring的编程式事务管理hibernate,很困恼的是,hibernate的事务都交给spring处理了,那我们在做操作的时候,如何知道操作是否成功?新手,对spring不熟悉。
比如这样子的一个:
-------------applicationContext.xml文件如下(有些内容省略掉了)
<beans>
<bean id="dataSource">
<!-- 略 -->
</bean>
<bean id="sessionFactory">
<!-- 略 -->
</bean>
<bean id="hibernateTemplate"
class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="DAOsupport" class="org.lxh.ssh.DAOSupport">
<property name="hibernateTemplate">
<ref bean="hibernateTemplate" />
</property>
</bean>
</beans>
---------------------------------------------------------
public class DAOSupport extends HibernateDaoSupport {
public void insert(Person person) {
this.getSession().save(person) ;
}
}
public class TestDemo {
public static void main(String[] args) {
ApplicationContext ctx = null ;
ctx = new ClassPathXmlApplicationContext("applicationContext.xml") ;
DAOSupport dao = (DAOSupport)ctx.getBean("DAOsupport") ;
Person per = new Person() ;
per.setName("fengzi") ;
per.setPassword("zzzzzz") ;
dao.insert(per) ; //如何判断这边是否操作成功或失败
}
}
问题是这样的:
pdi.insert(per) ; //如何判断这边是否操作成功或失败
我该怎么样该insert方法?
大虾们,帮帮