試圖更新一個實體,我火了REST請求:PUT <ip>/categories/5
用JSON體:{"id":"4","name":"otherCategory","contentList":[]}
@ManyToMany用的EclipseLink 2.5.2和2.4.4傑克遜
錯誤消息是:
WARN [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter]
(default task-27) Failed to evaluate deserialization for type [simple type, class
com.example.domain.assetmanagement.Category]: java.lang.IllegalArgumentException:
Can not handle managed/back reference 'users-roles': no back reference property
found from type [collection type; class java.util.List, contains [simple type,
class com.example.domain.user.permission.Role]]
Category.java不包含此關係,它只有三個屬性ID,名稱和contentList
@Id
@GeneratedValue(generator = "UUID_CATEGORY")
private String id;
@Column(name = "name")
private String name;
@OneToMany(mappedBy = "category")
@JsonManagedReference("category-content")
private List<Content> contentList;
[+getters/setters]
的關係在用戶和在角色定義,如所描述的在:http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Mapping/Relationship_Mappings/Collection_Mappings/ManyToMany
User.java:
@ManyToMany
@JoinTable(name = "user_role",
joinColumns = {
@JoinColumn(
name = "user_id",
referencedColumnName = "id"
)
},
inverseJoinColumns =
@JoinColumn(
name = "role_id",
referencedColumnName = "id"
)
)
@JsonManagedReference("users-roles")
private List<Role> roles;
Role.java:
@ManyToMany(mappedBy = "roles")
private List<User> users;
當我在Role.java添加@JsonBackReference到用戶的財產,我得到以下錯誤:
WARN [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter]
(default task-28) Failed to evaluate deserialization for type [simple type, class
com.example.domain.assetmanagement.Category]: java.lang.IllegalArgumentException:
Can not handle managed/back reference 'users-roles': back reference type
(java.util.List) not compatible with managed type (com.example.domain.user.User)
您可以使用不再有效的測試映射在您的類路徑上使用舊版本的類嗎?我不明白它會如何將用戶角色引用與類別類關聯。 – Chris
類別從未包含此關聯。我認爲它通過關係模式中的contentList和其他實體,直到它到達用戶角色。 – dexBerlin
現在我已經將@JsonIgnore添加到關係的兩側以使其工作。我分別獲取用戶/角色。 – dexBerlin