我正在使用mongodb with spring mvc
REST API。我有一个控制器,它为事件添加评论。该控制器使用我的事件服务的方法。它们的实现如下。但是在我看来,好像我的 mongodb 连接在没有transaction
. 我已经在我1 insert
的1 update
控制器中添加了评论。如果更新事件抛出错误,请求提交插入。为什么它不做回滚?我该如何解决这个问题?
public Comments addComment(Comments comment) throws Exception{
comment.setCommentDate(SowUtil.getDateTimeDB());
comment.setCommenter(personService.findPersonById("531cc90e3c37b20bef47dfc7"));
mongoTemplate.insert(comment);
Events adv = findEventById(comment.getEventId());
adv.addComment(comment);
eventService.save(adv);
return comment;
}