我有@Transactional方法的Spring bean。Spring @Transactional註釋的嚴格替代
public class ABean{
@Transactional
public void method aMethod(){
//do some job with Hibernate.
}
}
但現在我需要(實際上是在石英上下文)調用從不應在Spring上下文中被稱爲另一種方法,這種方法:
public class ABean implements org.quartz.Job{
@Transactional
public void method aMethod(){
//do some job with Hibernate.
}
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
System.out.println("start...");
//@Transactional annotation is ignored here
//so I have 'Could not obtain transaction-synchronized Session
//for current thread' exception.
aMethod();
System.out.println("done");
}
}
據我瞭解註解@Transactional只是不知何故包裝方法與另一些代碼。那麼我怎麼必須包裝aMethod()調用才能完全像Spring調用一樣調用它?
[Spring @Transaction方法調用由同一類中的方法調用可能的副本,不起作用?](http://stackoverflow.com/questions/3423972/spring-transaction-method-call-by-the-方法在同一班,不禾窩) –