代码如下
<bean id="txManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<tx:annotation-driven transaction-manager="txManager"/>services层代码:
@Service("stuServiceImpl")
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public class StuServiceImpl implements StuService { @Autowired
private StuDaoImpl stuDaoImpl;
public void saveAll(Student s, Score ss) {
stuDaoImpl.saveAll(s, ss);
}
}dao层代码@Repository("stuDaoImpl")
public class StuDaoImpl implements StuDao { @Autowired
private SessionFactory sessionFactory;
public void saveAll(Student s,Score ss) {
Session session = sessionFactory.openSession();
session.save(s);
session.save(ss);
}
}事物没有提交,原因可能是什么,
小白,刚接触spring
<bean id="txManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<tx:annotation-driven transaction-manager="txManager"/>services层代码:
@Service("stuServiceImpl")
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public class StuServiceImpl implements StuService { @Autowired
private StuDaoImpl stuDaoImpl;
public void saveAll(Student s, Score ss) {
stuDaoImpl.saveAll(s, ss);
}
}dao层代码@Repository("stuDaoImpl")
public class StuDaoImpl implements StuDao { @Autowired
private SessionFactory sessionFactory;
public void saveAll(Student s,Score ss) {
Session session = sessionFactory.openSession();
session.save(s);
session.save(ss);
}
}事物没有提交,原因可能是什么,
小白,刚接触spring
解决方案 »
- 求助dom4j1.6.1 Invalid XPath expression
- java排序待解决
- SQL DEFAULT 约束?
- 为啥我访问一个action 会跳转到另一个action里面
- 在webservice(xfire1.2+spring1.2+jdk1.4)中怎么才能调用在spring中注入的bean
- 页面显示条数问题!
- 跪求:用户自定义表单的代码
- openCms 6.0 安装求助 ?
- 求教:用过Struts + SessionBean + Hibernate架构开发程序的朋友请进来!(分不够到时再加)
- Spring mvc service层实现了两个接口如何注解
- 文件的上传下载,如何设计数据库的字段
- 如何实现一个过滤器
<!-- 该 BeanPostProcessor 将自动对标注 @Autowired 的 Bean 进行注入 -->
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/><bean id="txManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<tx:annotation-driven transaction-manager="txManager"/>
这种不是用@Resoure 么???还有你的session
Session session = sessionFactory.openSession()
改成:Session session =sessionFactory.getCurrentSession()