Spring Data JPA with MVC repository -
i building spring repository jpa-annotated entities. have created repository:
public interface apprepository extends pagingandsortingrepository<app, string> { }
the app class looks follows:
@entity public class app implements serializable { @id private string appid; @onetomany(mappedby = "app") private list<agentuser> agentusers; @onetomany(mappedby = "app") private list<appfacet> appfacets; // getters , setters go here }
where agentuser , appfacet hold reference property called app towards app object. in agentuser class, have changed restresource rel:
@entity public class agentuser { ... @manytoone @joincolumn(name = "appid") @restresource(rel = "agentusertoapp", exported = false) private app app; // other properties go here }
i getting following error message while querying /apps path:
org.springframework.http.converter.httpmessagenotwritableexception: not write content: infinite recursion (stackoverflowerror) (through reference chain: org.springframework.hateoas.pagedresources["_embedded"]);
do know causing it? please note have 1 app object in database, testing purposes , no other kind of object.
update
the trace is:
com.fasterxml.jackson.databind.ser.std.beanserializerbase.serializefields(beanserializerbase.java:677) com.fasterxml.jackson.databind.ser.beanserializer.serialize(beanserializer.java:156) com.fasterxml.jackson.databind.ser.defaultserializerprovider.serializevalue(defaultserializerprovider.java:129) com.fasterxml.jackson.databind.objectmapper.writevalue(objectmapper.java:2240) org.springframework.http.converter.json.abstractjackson2httpmessageconverter.writeinternal(abstractjackson2httpmessageconverter.java:231) org.springframework.http.converter.abstracthttpmessageconverter.write(abstracthttpmessageconverter.java:208) org.springframework.web.servlet.mvc.method.annotation.abstractmessageconvertermethodprocessor.writewithmessageconverters(abstractmessageconvertermethodprocessor.java:161) org.springframework.web.servlet.mvc.method.annotation.abstractmessageconvertermethodprocessor.writewithmessageconverters(abstractmessageconvertermethodprocessor.java:101) org.springframework.web.servlet.mvc.method.annotation.requestresponsebodymethodprocessor.handlereturnvalue(requestresponsebodymethodprocessor.java:167)
and after that, lot of:
org.springframework.data.mapping.model.basicpersistententity.dowithassociations(basicpersistententity.java:352) org.springframework.data.rest.webmvc.mapping.linkcollectingassociationhandler.dowithassociation(linkcollectingassociationhandler.java:101)
the problem resides in that, whenever have links entities, must implement repository entity too, in order generate proper links.
Comments
Post a Comment