日期:2014-05-19 浏览次数:20632 次
@Transactional public class Dao implements DaoIn{ private HibernateTemplate template; public void save(Student s){ try{ template.save(s); throw new RuntimeException(); } catch(RuntimeException e) { e.printStackTrace(); } } public HibernateTemplate getTemplate() { return template; } public void setTemplate(HibernateTemplate template) { this.template = template; } }
public class SpringAction extends ActionSupport{ private Student stu = new Student(); private DaoIn dao; public String execute()throws Exception{ stu.setName("111"); stu.setStuclassid(8); dao.save(stu); //this.wait(); return SUCCESS; }//省略get,set
<tx:annotation-driven/> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <bean id="SpringAction" class="test.web.SpringStruts2Hibernate.Action.SpringAction" scope="prototype"> <property name="dao" ref="dao" /> </bean> <bean id="dao" class="test.web.SpringStruts2Hibernate.DAOImpl.Dao"> <property name="template" ref="hibernateTemplate" /> </bean> <!--省略数据源的配置信息-->