I have a form, and this form should update my record, but apparently does not update, and I get below error message. Occupying this exception after 4 days, I decide to ask a question. If you need more information, I can add some.
JSP exception;
MergeContext#attempt to create managed -> managed mapping with different entities: [main.model.Users#1]; [main.model.Users#1]; nested exception is java.lang.IllegalStateException: MergeContext#attempt to create managed -> managed mapping with different entities: [main.model.Users#1]; [main.model.Users#1]
Java Exception
java.lang.IllegalStateException: MergeContext#attempt to create managed -> managed mapping with different entities: [main.model.Users#1]; [main.model.Users#1]
controller; get him information about the position of the user and the domain from the form and save it in the database;
@PostMapping("/save-personel-info") public String savePersonelInfo(@RequestParam int id, HttpServletRequest request, @ModelAttribute("Users") Users users, @ModelAttribute("Positions") Positions positions, @ModelAttribute("Domains") Domains domains, ModelMap model){ usersService.save(users); request.setAttribute("mode", "MODE_USERS"); return "redirect:/index"; }
Service
@Service @Transactional public class UsersService { public void save(Users users){ usersRepository.save(users); } }
The form
<form:form method="POST" action="/save-personel-info" modelAttribute="Users"> <tr> <form:input id="1-1-0" type="hidden" class="form-control" path="id"/> <td><form:input id="1-1-0" type="text" class="form-control" path="username" /></td> <td><form:input id="1-1-0" type="text" class="form-control" path="mail" /></td> <td> <form:select path="Positions" class="form-control"> <form:options items="${Pst}" itemValue="id" itemLabel="position_name" /> </form:select> </td> <td> <form:select path="Domains" class="form-control"> <form:options items="${Domains}" itemValue="id" itemLabel="domain_name" /> </form:select> </td> </tr> <input type="submit" value="Submit" /> </form:form>
Custom class
@Component @Entity public class Users { @Id @GeneratedValue(strategy = GenerationType.AUTO) public long id; public String username; public String mail; @Temporal(TemporalType.DATE) public Date enrolment_date; @ManyToOne(cascade = CascadeType.ALL) public Domains domains; @ManyToOne(cascade = CascadeType.ALL) public Positions positions; @OneToMany(targetEntity = UserLanguages.class, mappedBy = "users", cascade = CascadeType.ALL, fetch = FetchType.EAGER) public Set<UserLanguages> userlanguages = new HashSet<UserLanguages>(); @OneToMany(targetEntity = UserCertificates.class, mappedBy = "users", cascade = CascadeType.ALL, fetch = FetchType.EAGER) public Set<UserCertificates> usercertificates = new HashSet<UserCertificates>(); @OneToMany(targetEntity = UserKnowledge.class, mappedBy = "users", cascade = CascadeType.ALL, fetch = FetchType.EAGER) public Set<UserKnowledge> userknowledge = new HashSet<UserKnowledge>();
What is the meaning of "managed matching with different objects", I will investigate this error message, but I think no one will get this error. Hibernate-orm