Jax-b xml backward link with many for many relationships

In my data model, I have several different reasons. I am trying to use JAX = B to get XML representations in data models, however I read that for relationships from one to several:

@XmlInverseReference 

required for the back of the display. I believe that this is for using different types of sampling (e.g. LAZY and EAGER). I don’t know exactly how this annotation works. Does it use reverse pointers to ensure that data is not retrieved when specified in specific fields? I also don't know if I need to comment on many of the many relationships with the above annotation or not.

Here is a custom class that has many, many relationships with itself, i.e. the user can be friends with many other users. Should I annotate the getter with @XmlInverseReference?

 @Entity @Table(name = "users") public class User implements Serializable { ... // bi-directional many-to-many association to User @ManyToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH }) @JoinTable(name = "friends", joinColumns = { @JoinColumn(name = "uid") }, inverseJoinColumns = { @JoinColumn(name = "frienduId") }) private List<User> friends; /** * @return * * gets the list of users this user is friends with */ public List<User> getFriends() { return this.friends; } /** * @param friendsList * * sets the users friends list */ public void setFriends(List<User> friendsList) { this.friends = friendsList; } 

Any help or guidance is greatly appreciated.

+4
source share
1 answer

Note. I am an EclipseLink JAXB (MOXy) and a member of the JAXB Group (JSR-222) .

@XmlInverseReference is an EclipseLink JAXB (MOXy) extension that allows you to map bidirectional relationships:

@XmlInverseReference has two roles:

  • During sorting, it prevents the appearance of an infinite loop. If there is a bi-directional connection between Foo and Bar , it will marshal Foo , then Bar , and then it will stop before trying to marshal Foo again.
  • During unmarshalling, it will populate the backward pointer.
+1
source

Source: https://habr.com/ru/post/1485238/


All Articles