I know there are a lot of simiar errors already out there - and believe me, I tried most - but I simply can't fix this on my side. Generally I am using tapestry and resteasy to provide a REST service. Hibernate is my persistance framework. I have one Java object "Obj1" and another Java object "User". A user can own some Obj1's, so I have the following mapping for obj1 in the User:
@OneToMany(cascade = CascadeType.ALL, mappedBy = "owner")
private Set<obj1> obj1s;
And on the other side (in Obj1):
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "owner", referencedColumnName = "guid")
private User owner;
So the user owns some Obj1's, while the obj1 is aware of it's owner. This gives me a exception
org.jboss.resteasy.spi.UnhandledException: RESTEASY003770: Response is committed, can't handle exception
<<omitted>>
Caused by: org.codehaus.jackson.map.JsonMappingException: Infinite recursion (StackOverflowError)
I found this website and that and thought I was save...I tried doing the @JsonManagedReference, @JsonBackReference thing on both sides (I even flipped them to see if I just annotated the wrong side with @JsonManagedReference) but still the same exception. I also found the
@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="guid")
which I added to both sides (see here) but still nothing (guid is a property on both objects). I then found this and added
@JsonIdentityReference(alwaysAsId = true)
to the collection-property but still with the same effect. Of course the most obvious thing would have been to use @JsonIgnore
, found on the first link and here, but this didn't work either. Now I am thinking that the issue might be somewhere else, maybe my dependencies are not correct... However, I was using the com.fasterxml.jackson
-import (as this was suggested in some posts). The relevant section of my pom is:
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jsapi</artifactId>
<version>3.0.19.Final</version>
</dependency>
<dependency>
<groupId>com.wordnik</groupId>
<artifactId>swagger-jaxrs_2.10</artifactId>
<version>1.3.0</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson-provider</artifactId>
<version>2.3.4.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-multipart-provider</artifactId>
<version>3.0.4.Final</version>
</dependency>
<dependency>
<groupId>org.tynamo</groupId>
<artifactId>tapestry-resteasy</artifactId>
<version>0.4.0</version>
</dependency>
So, can anybody give me another hint or what I can still try to do? Of course, I could implement another object just for returing them via REST service and don't mix it with my objects for persistance. But I would definitely know how I can fix this issue...