json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -
json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -
hello have problem hibernate , jackson. have 2 pojos
@entity @table(name = "users") public class user implements serializable { static final long serialversionuid = 4235637833262722256l; @id @generatedvalue private int id; @column(name = "creation_date") private date creationdate; @column(name = "first_name") private string firstname; @column(name = "last_name") private string lastname; @version @column(name = "version") private int version; @column(name = "e_mail") private string email; @column(name = "enabled") private boolean enabled; @column(name = "login") private string login; @column(name = "password") private string password; @jsonmanagedreference("role") @onetomany(mappedby = "user", cascade = cascadetype.all,fetch = fetchtype.eager) private set<userrole> userrole;
user's , role that's made spring security integration.
@entity @table(name = "user_roles") public class userrole { @version @column(name = "version") int version; @id @generatedvalue private int id; @jsonbackreference("role") @manytoone() @joincolumn(name = "user_id", referencedcolumnname = "id") private user user; @column(name = "role") private string role;
and have controller create user json via jackson. method
@requestmapping(value = "/login", method = requestmethod.get, produces = "application/json") private @responsebody user checkloginavailability(@requestparam string login) { user user = appcontext.getuserservice().readuserbylogin(login); if (user != null) { homecoming user; } homecoming new user(); }
when method homecoming user without null fields throws that:
26-oct-2014 14:31:17.652 warning [http-nio-8080-exec-4] org.springframework.web.servlet.mvc.support.defaulthandlerexceptionresolver.doresolveexception handling of [org.springframework.http.converter.httpmessagenotwritableexception] resulted exception java.lang.illegalstateexception: cannot phone call senderror() after response has been committed
that's problem came when added @onetomany(mappedby = "user", cascade = cascadetype.all,fetch = fetchtype.eager), fetch = fetchtype.eager, wasn't able save user role in case table user_role empty. i've reddish solution problem in infinite loop somewhere in jackson, added anotation @jsonbackreference("role") , @jsonmanagedreference("role") nil changed. how can solve problem? give thanks you!
i recommend adding @jsonignore
on property causing circular reference. tell jackson not serialize property.
java json hibernate orm jackson
Comments
Post a Comment