I have a Spring bean with @Transactional method.
public class ABean{
@Transactional
public void method aMethod(){
//do some job with Hibernate.
}
}
But now I need to call this method from another method which should be called not in Spring context (in Quartz context actually):
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");
}
}
As I understand annotation @Transactional just somehow wraps method with some another code. So how I must wrap aMethod() call to call it exactly like Spring calls?