我有異步的Web服務方法,我想發送responce 202(接受),並做與數據庫相同的更改。我如何使用JPA實現它? 這裏我服務的方法:異步的Web服務JPA
@Transactional
public void createTask(@Suspended AsyncResponse response){
new Thread(){
public void run(){
RequestTask requestTask = new RequestTask();
requestTask.setAim("all tables");
requestTask.setDescription("Update Tables");
requestTask.setOwner("John Calagan");
requestTaskDao.createRequestTask(requestTask);
}
}.start();
Response acceptedResponse = Response.status(Response.Status.ACCEPTED).build();
response.resume(acceptedResponse);
}
吾道級別:
@PersistenceContext(unitName = "administration")
private EntityManager entityManager;
@Override
public void createRequestTask(RequestTask requestTask) {
entityManager.persist(requestTask);
}
但我有一個例外:
Exception in thread "Thread-6" javax.persistence.TransactionRequiredException: No EntityManager with actual transaction available for current thread - cannot reliably process 'persist' call at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityMa nagerInvocationHandler.invoke(SharedEntityManagerCreator.java:282) at com.sun.proxy.$Proxy33.persist(Unknown Source) at...
我怎樣才能解決這個問題呢?
忘了說我在課堂上註釋@Transactional – Vas9IH
你可以編輯你的問題。 – talex
謝謝,我沒有注意到 – Vas9IH