【发布时间】:2015-04-01 08:56:05
【问题描述】:
Class MyTestBean {
public void requiredMethod(){
//somehow call the "requiresNewMethod" with a new transaction
//provided from the container
this.requiresNewMethod(); //this does not work.. no new transaction is created
}
public void requiresNewMethod(){ //code..}
}
蓝图 xml:
<bean id="myTestBean "
class="MyTestBean ">
<jpa:context property="entityManager" unitname="sample" />
<tx:transaction method="requiredMethod" value="Required" />
<tx:transaction method="requiresNewMethod" value="RequiresNew" />
</bean>
当 requiredMethod 被调用时,JPA 管理器创建一个新事务(如果它还没有在事务中)。我想从“requiredMethod”内部调用方法“requiresNewMethod”,并强制 JPA 管理器创建一个新的(嵌套)事务。
例如,如果上面是 EJB 并且我在 EJB 容器中,我可以这样做
public void requiredMethod(){
sessionContext.getBusinessObject(MyTestBean.class).requiresNewMethod();
}
【问题讨论】:
标签: osgi apache-karaf blueprint-osgi