0

How to implement a database transaction in api gateway?

 @Transactional
 @RequestMapping(value = UserConstants.USERS_PATH, method = RequestMethod.POST)
  public void save(@RequestBody User user) {
    //save two model
    UserEntity ue = userService.save(user.reverseEntity());
    VideoEntity ve = videoService.save(user.getVideo().reverseEntity());
   //service load by eureka + feign
  }

I want save two model with different service in one transaction.

Dreampie
  • 1,321
  • 4
  • 17
  • 32
  • Could you be a bit more specific about the concrete goal you try to achieve? – Mike Boddin Dec 14 '15 at 10:11
  • I want save one user contains videos,save user and video two model with two service in one transaction – Dreampie Dec 15 '15 at 06:25
  • So what did you tried so far, why didn't it work? I think it could be helpful if you provide some sample code in your question, pointing to the concrete part, your question belongs to. I looked in your sample-project but I can just find a User-Model and a Controller. I think you need to be a **lot** more specific to get helpful answers ;-) – Mike Boddin Dec 15 '15 at 07:24
  • i edit question,hope you understand it. – Dreampie Dec 15 '15 at 08:01
  • Thanks for clarification. Doesn't the @Transactional Annotation provide the behaviour you expect? – Mike Boddin Dec 15 '15 at 09:01
  • @Transactional not work in controller – Dreampie Jan 15 '16 at 04:38
  • Maybe you could create a "Wrapper-Service" which encapsulates the userService and videoService methods? This can be called from Controller then. `@Service public class WrapperService{ @Transactional public void save(User user){ UserEntity ue = userService.save(user.reverseEntity()); VideoEntity ve = videoService.save(user.getVideo().reverseEntity()); //... } } ` – Mike Boddin Jan 15 '16 at 09:28

0 Answers0