- Spring MVC 3.1.1 RELEASE
- Spring Data JPA 1.1.0 RELEASE
- Hibernate 3.6.9.Final
Weitere Ergebnisse:
1) Wenn ich mit der @Transactional-Methode von einem anderen Dienst Anmerkungen mache, wird eine Transaktion erstellt.
Code: Select all
21:49:13.397 [DEBUG] (http-8080-2) org.springframework.orm.jpa.JpaTransactionManager - Creating new transaction with name [com.xen.components.page.PageServiceImpl.findAllOrdered]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; ''
3) Beide Dienste im Root-Anwendungskontext. Ausgabe von log.error(context):
Code: Select all
OrderServiceImpl - Root WebApplicationContext: startup date [Tue Sep 17 21:48:30 FET 2013]; root of context hierarchy
PageServiceImpl - Root WebApplicationContext: startup date [Tue Sep 17 21:48:30 FET 2013]; root of context hierarchy
Code: Select all
@Service
public class OrderServiceImpl extends CRUDServiceImpl implements OrderService {
private static final Logger log = Logger.getLogger(OrderServiceImpl.class);
@Autowired
private OrderRepository repo;
@Autowired
private OrderItemService orderItemService;
@Override
protected CRUDRepository getRepository() {
return repo;
}
@Override
@Transactional(propagation=Propagation.REQUIRES_NEW)
public Order save(Order entity) {
if (entity.getCreationDate() == null) {
entity.setCreationDate(new Date());
}
if (entity.getId() == null) {
increasePopularityForProductsInOrder(entity);
// throws NoTransactionException: No transaction aspect-managed TransactionStatus in scope
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
decreaseStockNumberForSkusInOrder(entity);
}
return super.save(entity);
}
private void increasePopularityForProductsInOrder(Order order) {
List items = order.getItems();
for (OrderItem item : items) {
orderItemService.increasePopularity(item);
}
}
private void decreaseStockNumberForSkusInOrder(Order order) {
List items = order.getItems();
for (OrderItem item : items) {
orderItemService.removeFromStock(item);
}
}
}
Hier ist meine Konfiguration:
applicationContext.xml
Code: Select all
Code: Select all
404
404
/WEB-INF/layouts/layouts.xml
/WEB-INF/views/**/views.xml
Code: Select all
org.hibernate.ejb.HibernatePersistence
CartController.java
Code: Select all
@Controller
public class CartController {
private static final Logger log = Logger.getLogger(CartController.class);
...
@RequestMapping(value = "/cart/submit-order", method = RequestMethod.POST)
public String submit(@RequestParam String email, @RequestParam long deliveryType, Model uiModel, HttpServletRequest request, RedirectAttributes redirectAttrs) {
Order order = CartHelper.getOrderFromRequest(request);
uiModel.addAttribute("email", email);
// 1. check if address is set
if (StringUtil.isEmpty(order.getClientInfo().getFirstName())) {
MessageBean.createErrorMessage("cart.enter-address.error").displayMessage(uiModel);
populateForm(uiModel, order);
return "cart";
}
// 2. check if specified deliveryType exist
DeliveryType type = null;
try {
type = deliveryTypeService.findOne(deliveryType);
} catch (NotFoundException nfe) {
MessageBean.createErrorMessage("cart.invalid-delivery-type.error").displayMessage(uiModel);
populateForm(uiModel, order);
return "cart";
}
order.setDeliveryType(type);
// 3. check if email is valid
if (!StringUtil.isEmailValid(email)) {
MessageBean.createErrorMessage("cart.invalid-email.error").displayMessage(uiModel);
populateForm(uiModel, order);
return "cart";
}
order.getClientInfo().setEmail(email);
// 4. check if order is not empty
if (order.isEmpty()) { // should not be possible
log.warn("Empty order submission registered! " + order);
return "cart/empty";
}
order = orderService.save(order);
CartHelper.updateOrderForRequest(request, order);
// 5. send notification to client
try {
sendNotificationToClient(order, request);
redirectAttrs.addFlashAttribute(MessageBean.MESSAGE_BEAN_KEY, MessageBean.createSuccessMessage("cart.order.successfuly.created"));
} catch (Exception e) {
redirectAttrs.addFlashAttribute(MessageBean.MESSAGE_BEAN_KEY, MessageBean.createErrorMessage("cart.failed.to.send.notification.during.order.saving"));
}
return "redirect:/orders/success";
}
...
}
Mobile version