Answer the question
In order to leave comments, you need to log in
How to fix org.springframework.dao.InvalidDataAccessApiUsageException: detached entity passed to persist: com.model.User?
Hello catching this error - org.springframework.dao.InvalidDataAccessApiUsageException: detached entity passed to persist: com.model.User; help to understand
the service layer is the @Transactional annotation, at the class level, that is, everything happens in a separate transaction.
There are three roles already recorded in the database, and when I try to update the role, add a link to the user to it, I grab this error. As I understand it, at the time of updating the user object is disabled and he cannot update.
Note - If the role has no users attached yet, then no error occurs.
test method
@Test
public void writingStartValuesOnDBTest() {
Role role = new Role();
User user3 = new User("Alex3", "Login3",
"[email protected]", "4444444444", LocalDate.now(), role);
role = roleService.findByRoleName("user");
user3.setRole(role);
role.getUsers().add(user3);
roleService.update(role);
@Override
public void update(Role role) {
Role role1 = roleDAO.findById(role.getId_role());
if(role1 != null){
role1.setUsers(role.getUsers());
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question