Vladislav Babin created OLINGO-1522: ---------------------------------------
Summary: @JoinTable links are not updated correctly Key: OLINGO-1522 URL: https://issues.apache.org/jira/browse/OLINGO-1522 Project: Olingo Issue Type: Bug Components: odata2-jpa Affects Versions: V2 2.0.11 Reporter: Vladislav Babin I have a classic setup of users, roles and user_roles table. Users are defined as follows: {code:java} @Entity @Table(name = "users") public class User implements Serializable { ... @Getter @Setter @ManyToMany(cascade = {CascadeType.ALL}) @JoinTable(name = "user_roles", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "role_id"), uniqueConstraints = {@UniqueConstraint(columnNames = {"user_id", "role_id"})} ) Role.class) private List<Role> roles; ... }{code} The problem is when I execute PATCH (PUT, MERGE) on Users endpoint {code:java} PATCH http://localhost:8080/admin/rest/odata/Users(7) { "RoleDetails":[ { "__metadata":{ "id":"http://localhost:8080/admin/rest/Roles(3L)", "uri":"http://localhost:8080/admin/rest/Roles(3L)", "type":"default.Role" }, "Code":"ROLE8", "Id":"3", "Name":"Role 8" } ] } {code} and the user already has the role then I get an error that roots to PostgreSQL's {code:java} ERROR: duplicate key value violates unique constraint "pk_user_roles" {code} At the same time when I run update with plain JPA repository it succeeds: {code:java} @PUT @Path("/{id}") @Produces("application/json") public User put(@Context SecurityContext securityContext, @PathParam("id") Long id, User user){ return userRepository.saveAndFlush(user); } {code} Adding @EdmNavigationProperty annotation did not help: {code:java} @Getter @Setter @ManyToMany(cascade = {CascadeType.ALL}) @JoinTable(name = "user_roles", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "role_id") ) @EdmNavigationProperty(toMultiplicity = Multiplicity.MANY, toType = Role.class) private List<Role> roles; {code} OData app uses Spring Boot entity manager as in this tutorial: https://www.baeldung.com/odata The question is: shoudn't olingo check for existing records in a join table? how can I further investigate the issue? Any working example of olingo2 + JPA + @JoinTable would be highly appreciated. -- This message was sent by Atlassian Jira (v8.3.4#803005)