【发布时间】:2016-06-27 02:33:32
【问题描述】:
正如我在这个问题中所述,我正在尝试在两个表之间添加连接:Adding table joins to existing project causes infinite recursion
但是现在我收到了一个新错误:
detached entity passed to persist: sample.todosapp.spring.domain.User] with root cause
当我尝试调用此代码时(这是在我的 REST 控制器中修改后的 POST 方法):
@RequestMapping(method = POST)
@ResponseStatus(HttpStatus.CREATED)
public Callable<Todo> post(@RequestBody Todo todo) {
User u = userService.findBySso(SecurityContextHolder.getContext().getAuthentication().getName());
todo.setUser(u);
return () -> todoRepository.save(todo);
}
如何在 POST 期间添加连接?
【问题讨论】:
-
我不完全理解 post 和 join 之间的问题(这是两个完全不同的概念),但是对于您的错误,您需要使用 saveOrUpdate() 方法
标签: java mysql spring hibernate rest