首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何理解PROPAGATION_REQUIRED

如何理解PROPAGATION_REQUIRED
EN

Stack Overflow用户
提问于 2012-11-02 11:25:11
回答 1查看 198关注 0票数 0

我还是不明白以下几点:

代码语言:javascript
复制
method xxx{
    Teacher t=dao.get(new Teacher(1));
    t.setName("mark"); 

    finder.find(Teacher.class,null,null,null);

    dao.getSf().getCurrentSession().evict(t);               

    t.setName("ff"); 
    return t;
}

xxxfinder.find都在tx控制下,需要传播,但我发现只有第一个修改提交给db。当我删除find方法时,没有提交任何修改。为什么会这样呢?

好的,下面是我的代码:

代码语言:javascript
复制
public List<T> find(Class<T> bean, Map<String, Object> param,Pageable pg,Sortable od) {
    //from Questionair t where 1=1
    String hql="from "+this.getBeanName(bean)+" "+this.allias+" where 1=1 "+this.getWhereCourse(param)+" ";
    if(od!=null && od.getDir()!=null && od.getSort()!=null){
        hql+="order by "+this.allias+"."+od.getSort()+" "+od.getDir();
    }
    //开始查询
    Session s=sf.getCurrentSession();
    Query q=sf.getCurrentSession().createQuery(hql);
    if(pg!=null){
        q.setFirstResult(pg.getStart());
        q.setMaxResults(pg.getStart()+pg.getLimit());
    }
    System.out.println(q);
    return q.list();
}

和QuestionairService中的xxx方法:

代码语言:javascript
复制
    try{
        Teacher t=dao.get(new Teacher(1));
        t.setName("mark"); 

        //-------------
        System.out.println("加入finder");
        finder.find(Teacher.class,null,null,null);

        //-------------
        System.out.println("加入evict");
        dao.getSf().getCurrentSession().evict(t);


        t.setName("ff"); 
        return t;
    }

下面是我的配置

代码语言:javascript
复制
<tx:advice id="txAdvice" transaction-manager="tm">
    <tx:attributes>
        <tx:method name="*" propagation="REQUIRED" />
        <!--  <tx:method name="find" propagation="REQUIRES_NEW"/> -->
    </tx:attributes>
</tx:advice>
<aop:config>
    <aop:pointcut id="allService" expression="(execution(* com.etc.ssh.service.*.*(..)))" />
    <aop:pointcut id="allFinders" expression="(execution(* com.etc.ssh.finder.*.find(..)))" />
    <aop:pointcut id="allSession" expression="(execution(* *.getCurrentHttpSession(..)))" />
    <aop:advisor pointcut-ref="allService" advice-ref="txAdvice"/>
    <aop:advisor pointcut-ref="allFinders" advice-ref="txAdvice"/>
</aop:config>

<aop:config proxy-target-class="true">
    <aop:advisor pointcut-ref="allSession" advice-ref="ssAdvice"/>
</aop:config>
EN

回答 1

Stack Overflow用户

发布于 2012-11-02 16:12:54

调用evict()可防止对象随后被持久化。要“重新持久化”它,您需要再次调用save()

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13188881

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档