解决方案 »
- struts2 action到jsp js获得参数 参数传递问题
- j2ee首页如何生成静态页面
- 高分求教百度笔试题答案!
- 有人用过jetty吗?我的jsp里el三元运算符不好用啊
- java中stack overflow,如何解决,在线等待。
- JMS 发送ObjectMessage问题
- 求救!哪位高人帮我解答一下,关于JSP+SQL SERVER 2000的编程问题
- 编译jbuilder工程时出错,但是源程序时没有问题的,请帮我看看!
- 关于spring整合hibernate的问题
- ssh项目中配置两个连接池对性能还有效率有好处吗
- java.net.SocketException: Connection reset错误
- cas单点登录的权限问题
<bean id"txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory">
</bean>
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="save*"/>
<tx:method name="update*"/>
<tx:method name="delete*"/>
<tx:method name="*" propagation="supports"/>
</tx:attributes>
</tx:advice>
<aop:config proxy-target-class="true">
<aop:advisor pointcut="execution(* com.demos.service..*.*Impl.* (..))"
advice-ref="txAdvice"/>
</aop:config>
我的事务加在了service层,但只有查询和插入数据能发出sql语句,在web.xml中我也把OpenSessionInView这个类配置在了struts2的拦截器之前,可还是没有用
private SessionFactory sessionFactory;
@Autowired
public void setSessionFactory(SessionFactory sessionFactory){this.sessionFactory=sessionFactory;}
public Session getCurrentSession(){
return this.sessionFactory.getCurrentSession();
}
public void update(User user){
this.getCurrentSession().update(user);
}
public void delete(int id){
this.getCurrentSession().delete(findUser(id));
public User findUser(int id){
return (User)this.getCurrentSession().load
(User.class,id);}
<tx:advice id="txadvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="create" propagation="REQUIRED" />
<!--hibernate4必须配置为开启事务 否则 getCurrentSession()获取不到-->
<tx:method name="*" propagation="REQUIRED" read-only="true" />
</tx:attributes>
</tx:advice>试试这样呢?那个create是创建的方法create(),然后在dao里面用getSession().save(user);方法。。