我在现有系统上工作,需要让我的 spring 事务管理器附加到从主作业线程产生的线程。我不断收到这个异常
org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
at org.springframework.orm.hibernate3.SpringSessionContext.currentSession(SpringSessionContext.java:63)
at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:687)
at parity.model.datamapping.RefreshTask.execute(RefreshTask.java:95)
at com.paritysys.tasks.ASyncTask$1.run(ASyncTask.java:48)
at java.lang.Thread.run(Thread.java:662)
我用事务注释注释了我能想到的所有内容,但我仍然无法清除此错误。
我错过了什么
我的方法
@TransactionAS400
@TransactionScores
public void refresh() {
ASyncTaskWorker worker = new ASyncTaskWorker() {
public void progress(double percentage, String message) {
logger.debug(String.format("%.2f - %s", percentage, message));
}
public void handleException(Throwable e) {
try {
status.allowUpdating(property.getSchema());
} catch (Exception b) {
// consume
}
logger.error("Failed to complete the refresh task", e);
}
public void done(boolean success) {
status.allowUpdating(property.getSchema());
logger.debug(String.format(
"Reset updating status to default for %s",
property.getSchema()));
}
};
RefreshTask refTask = ServiceProviderContext.find(RefreshTask.class);
refTask.init(property, worker);
ASyncTaskHandler.getInstance().add(refTask);
ASyncTaskHandler.getInstance().process();
}