日期:2014-05-17 浏览次数:20697 次
<bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<tx:annotation-driven transaction-manager="txManager"/>
public class EmployeeService implements EmployeeServiceInter {
@Transactional
public void addEmployee(Employee e) {
// TODO Auto-generated method stub
sessionFactory.getCurrentSession().save(e);
}
}
怎么能方便的得到会话工厂呢?
public class LoginAction extends ActionSupport {
private EmployeeServiceInter employeeServiceInter;
/**
* @return
*/
public String execute() {
employeeServiceInter.addEmployee(employee);
}
public void setEmployeeServiceInter(EmployeeServiceInter employeeServiceInter) {
this.employeeServiceInter = employeeServiceInter;
}