Reputation: 69
What I understand so far is that when you use the @Transactional annotation any failure will cause the operation to rollback to its previous state.I have this method which adds Items to a quotation using spring PagingAndSortingRepository Interface.
@Override
public Quotation createNewQuotation(PurchaseRequest purchaseRequest, Supplier supplier) {
Quotation quotation = new Quotation();
Date now = new Date(Calendar.getInstance().getTimeInMillis());
quotation.setQuotationDate(now);
quotation.setPurchaseRequest(purchaseRequest);
quotation.setSupplier(supplier);
quotationRepository.save(quotation);
return quotation;
}
When I put a @Transactional annotation on the whole class and manually testing if the operation will rollback (by not selecting any supplier), other properties like quotationDate, PurchaseRequest is still stored in the database.
I get the feeling that I'm not using the @Transactional annotation. What might be the problem and what can I do to fix it?
Upvotes: 0
Views: 727
Reputation: 69
Thanks for the replies.
I made this work by adding a @EnableTransactionManagement
on my main class.
I solved the
The bean 'purchaseRequestServiceImpl' could not be injected as a 'com.eprocurement.service.PurchaseRequestServiceImpl' because it is a JDK dynamic proxy that implements: com.eprocurement.service.PurchaseRequestService Action: Consider injecting the bean as one of its interfaces or forcing the use of CGLib-based proxies by setting proxyTargetClass=true on @EnableAsync and/or @EnableCaching.
by placing the @Transactional
annotation on my service interfaces and @autowiring
it instead of @autowiring
my implementation classes.
Upvotes: 1