When I call findById method from User, a result is received, however when I try to convert the return from webservice, this exception is thrown:
org.codehaus.jackson.map.JsonMappingException: Infinite recursion (StackOverflowError) (through reference chain: com.empsys.user.User["locations"]->org.hibernate.collection.internal.PersistentBag[0]->com.empsys.contact.details.Location["contact"]->com.empsys.user.User["locations"]->org.hibernate.collection.internal.PersistentBag[0]->com.empsys.contact.details.Location["contact"]->com.empsys.user.User["locations"]->org.hibernate.collection.internal.PersistentBag[0]->com.empsys.contact.details.Location["contact"]->com.empsys.user.User["locations"]->org.hibernate.collection.internal.PersistentBag[0]->com.empsys.contact.details.Location["contact"] ...
The classes relationship is:
Class Contact - This class was created to represents multiple types of contacts on system.
@Entity
@Table(name = "CONTACT", uniqueConstraints = {@UniqueConstraint(columnNames = {"id"})})
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "CONTACT_TYPE")
public class Contact implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy="contact")
    @Column(nullable = true)
    @JsonManagedReference
    private List<Location> locations;
...
Class User - This class was created to represent Users with specific information
@Entity
@Table(name = "USER")
@DiscriminatorValue("USER")
public class User extends Contact {
...
Class Location - This class was created to represent addresses of users and others contacts of system
@Entity
@Table(name = "LOCATION", uniqueConstraints = {@UniqueConstraint(columnNames = {"id"})})
public class Location implements Serializable {
    @ManyToOne
    @JoinColumn(name = "contact_id", nullable = false)
    @JsonBackReference
    private Contact contact;
    ...
Dependencies used:
- (com.sun.jersey)jersey-json: version 1.18
- (com.fasterxml.jackson.datatype)jackson-datatype-hibernate4: version: 2.4.0
Could anyone help me?
 
     
     
     
    