It took me hours to realize, what the problem is:
I have a Spring Rest service and a GET-Method which returns a user in JSON-Format. The data comes from my database over sessionFactory.
After debugging it turned out, that the Problem is related to my bidrectional onetomany-manytoone relationship.
So calling
User user = (User) sessionFactory.getCurrentSession().load(User.class, userId);
returns a User-Object where user.getCity().getSupplier() runs into an com.sun.jdi.InvocationException. Therefore Jackson is obviously unable to serialize. But what causes this exception?
@Entity
@Table(name = "T_CITY")
public class City implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private long id;
@OneToMany(mappedBy = "city", cascade=CascadeType.ALL)
private Set<User> user;
@OneToMany(mappedBy = "city", cascade=CascadeType.ALL)
private Set<Supplier> supplier;
User:
@Entity
@Table(name = "T_USER")
public class User implements Serializable {
private static final long serialVersionUID = 1L;
public User() {
}
@Id
private long id;
@ManyToOne
private City city;
Supplier:
@Entity
@Table(name = "T_SUPPLIER")
public class Supplier implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private long id;
@ManyToOne
private City city;