I have two objects that display bi-directionally. A vehicle with a collection of registrations and registration. These objects are displayed as REST services.
@Entity
@XmlRootElement
public class Vehicle implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String brand;
private String type;
@OneToMany(mappedBy = "vehicle", fetch = FetchType.EAGER)
private List<Registration> registrations;
}
The problem is that FetchType.EAGER creates infinite recursion .
@Entity
@XmlRootElement
public class Registration implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
@ManyToOne
private Vehicle vehicle;
}
After some research, it turned out that in order to solve the problem, I need to add the @JsonIdentityInfo annotation (generator = ObjectIdGenerators.PropertyGenerator.class, property = "id") to the Vehicle class.
My question is: what does the PropertyGenerator class do?
source
share