Filter user by Role cause a infinity recursion The 2019 Stack Overflow Developer Survey Results Are InWrong ordering in generated table in jpaHow can i do a multiselect in jsp/jstl with selected value?How to deserialize a list using GSON or another JSON library in Java?Why this class should implement java.io.Serializable when I using hibernate?PostgreSQL error: Fatal: role “username” does not existHow to change PostgreSQL user password?Json parsing in android using restTemplate (BEGIN_ARRAY but was BEGIN_OBJECT)Spring MVC form validation does't work for nested complex typesHibernate : Why FetchType.LAZY-annotated collection property eagerly loading?How enforce a p:inputText value to be set through p:ajax if the JSR 303 validation constraint is violated?
Old scifi movie from the 50s or 60s with men in solid red uniforms who interrogate a spy from the past
Falsification in Math vs Science
What do these terms in Caesar's Gallic Wars mean?
A female thief is not sold to make restitution -- so what happens instead?
What do I do when my TA workload is more than expected?
Is bread bad for ducks?
RequirePermission not working
"as much details as you can remember"
Is it ok to offer lower paid work as a trial period before negotiating for a full-time job?
Why does the nucleus not repel itself?
Does adding complexity mean a more secure cipher?
How much of the clove should I use when using big garlic heads?
How to add class in ko template in magento2
How to type a long/em dash `—`
Can there be female White Walkers?
Worn-tile Scrabble
How did passengers keep warm on sail ships?
Why can I use a list index as an indexing variable in a for loop?
How to support a colleague who finds meetings extremely tiring?
How can I define good in a religion that claims no moral authority?
Why doesn't UInt have a toDouble()?
Output the Arecibo Message
Why are there uneven bright areas in this photo of black hole?
Why is the maximum length of OpenWrt’s root password 8 characters?
Filter user by Role cause a infinity recursion
The 2019 Stack Overflow Developer Survey Results Are InWrong ordering in generated table in jpaHow can i do a multiselect in jsp/jstl with selected value?How to deserialize a list using GSON or another JSON library in Java?Why this class should implement java.io.Serializable when I using hibernate?PostgreSQL error: Fatal: role “username” does not existHow to change PostgreSQL user password?Json parsing in android using restTemplate (BEGIN_ARRAY but was BEGIN_OBJECT)Spring MVC form validation does't work for nested complex typesHibernate : Why FetchType.LAZY-annotated collection property eagerly loading?How enforce a p:inputText value to be set through p:ajax if the JSR 303 validation constraint is violated?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
Overview
I'm learning Angular Java and JHipster, and I'm trying to filter the Users by Role but im getting a infinity recursion.
this is my userRepository.java
@Query(value = "select user from User user inner join user.authorities authorities where authorities.name =:role")
List<User> findByRole(@Param("role") String role);
I trying to do a inner join between the user table and the user_authority table, im parsing the role like a String "ROLE_ADMIN"
Upadte
Found something in the model if i do this select user.login
instead of select users
don't get the recursion error, so I think is maybe cause in the model is calling itself several times.
I have a relationship 1:1 with a another entity called extendedUser (for save additional information) and in extendedUser i have another relationship with user called coordinator so I think the model is calling itself.
This is just a part of the recursion in the console:
2019-03-22 14:08:32.082 WARN 12044 --- [ XNIO-2 task-9] .m.m.a.ExceptionHandlerExceptionResolver : Resolved exception caused by Handler execution: org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Infinite recursion (StackOverflowError); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Infinite recursion (StackOverflowError) (through reference chain:["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]
And this is my DTO on extended user when i think I have the problem
/**
* A DTO for the ExtendedUser entity.
*/
public class ExtendedUserDTO extends UserDTO implements Serializable
private final Logger log = LoggerFactory.getLogger(ExtendedUserDTO.class);
private Long id;
private String puesto;
private BigDecimal sueldo;
private LocalDate fechaIngreso;
private Long usuarioId;
//private Long coordinadorId;
private Set<Area> areas = new HashSet<>();
private Long coordinadorId;
private String coordinadorLogin;
private User coordinador;
private Set<Desarrollo> desarrollos = new HashSet<>();
public ExtendedUserDTO()
public ExtendedUserDTO(User user)
super(user);
this.puesto = user.getExtendedUser().getPuesto();
this.sueldo = user.getExtendedUser().getSueldo();
this.fechaIngreso = user.getExtendedUser().getFechaIngreso();
this.id = user.getId();
this.usuarioId = user.getId();
this.coordinadorLogin = user.getExtendedUser().getCoordinador().getLogin();
this.coordinadorId = user.getExtendedUser().getCoordinador().getId();
this.coordinador = user.getExtendedUser().getCoordinador();
Hibernate.initialize(user.getExtendedUser().getAreas());
this.areas = user.getExtendedUser().getAreas();
Hibernate.initialize(user.getExtendedUser().getDesarrollos());
this.desarrollos = user.getExtendedUser().getDesarrollos();
public Long getId()
return id;
public void setId(Long id)
this.id = id;
public String getPuesto()
return puesto;
public void setPuesto(String puesto)
this.puesto = puesto;
public BigDecimal getSueldo()
return sueldo;
public void setSueldo(BigDecimal sueldo)
this.sueldo = sueldo;
public LocalDate getFechaIngreso()
return fechaIngreso;
public void setFechaIngreso(LocalDate fechaIngreso)
this.fechaIngreso = fechaIngreso;
public Long getUsuarioId()
return usuarioId;
public void setUsuarioId(Long userId)
this.usuarioId = userId;
/* public void setCoordinadorId(Long userId)
this.coordinadorId = userId;
public Long getCoordinadorId()
return coordinadorId;
*/
public User getCoordinador()
return coordinador;
public void setCoordinador(User user)
this.coordinador = user;
public Set<Area> getAreas()
return areas;
public void setAreas(Set<Area> areas)
this.areas = areas;
public Set<Desarrollo> getDesarrollos()
return desarrollos;
public void setDesarrollos(Set<Desarrollo> desarrollos)
this.desarrollos = desarrollos;
public Long getCoordinadorId()
return coordinadorId;
public void setCoordinadorId(Long userId)
this.coordinadorId = userId;
public String getCoordinadorLogin()
return coordinadorLogin;
public void setCoordinadorLogin(String userLogin)
this.coordinadorLogin = userLogin;
@Override
public boolean equals(Object o)
@Override
public int hashCode()
return Objects.hashCode(getId());
@Override
public String toString()
return "ExtendedUserDTO" +
"id=" + getId() +
", puesto='" + getPuesto() + "'" +
", sueldo=" + getSueldo() +
", fechaIngreso='" + getFechaIngreso() + "'" +
", usuario=" + getUsuarioId() +
", coordinador='" + getCoordinadorLogin() + "'" +
"";
Notes
- I'm really new on Angular, Java, and Jhipster.
- Please if I missed something important, let me know on the comment
and I will added to the question. - Im just trying to get only the ADMIN users so if you have a better
way I really would like to know
java spring postgresql jpa jhipster
add a comment |
Overview
I'm learning Angular Java and JHipster, and I'm trying to filter the Users by Role but im getting a infinity recursion.
this is my userRepository.java
@Query(value = "select user from User user inner join user.authorities authorities where authorities.name =:role")
List<User> findByRole(@Param("role") String role);
I trying to do a inner join between the user table and the user_authority table, im parsing the role like a String "ROLE_ADMIN"
Upadte
Found something in the model if i do this select user.login
instead of select users
don't get the recursion error, so I think is maybe cause in the model is calling itself several times.
I have a relationship 1:1 with a another entity called extendedUser (for save additional information) and in extendedUser i have another relationship with user called coordinator so I think the model is calling itself.
This is just a part of the recursion in the console:
2019-03-22 14:08:32.082 WARN 12044 --- [ XNIO-2 task-9] .m.m.a.ExceptionHandlerExceptionResolver : Resolved exception caused by Handler execution: org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Infinite recursion (StackOverflowError); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Infinite recursion (StackOverflowError) (through reference chain:["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]
And this is my DTO on extended user when i think I have the problem
/**
* A DTO for the ExtendedUser entity.
*/
public class ExtendedUserDTO extends UserDTO implements Serializable
private final Logger log = LoggerFactory.getLogger(ExtendedUserDTO.class);
private Long id;
private String puesto;
private BigDecimal sueldo;
private LocalDate fechaIngreso;
private Long usuarioId;
//private Long coordinadorId;
private Set<Area> areas = new HashSet<>();
private Long coordinadorId;
private String coordinadorLogin;
private User coordinador;
private Set<Desarrollo> desarrollos = new HashSet<>();
public ExtendedUserDTO()
public ExtendedUserDTO(User user)
super(user);
this.puesto = user.getExtendedUser().getPuesto();
this.sueldo = user.getExtendedUser().getSueldo();
this.fechaIngreso = user.getExtendedUser().getFechaIngreso();
this.id = user.getId();
this.usuarioId = user.getId();
this.coordinadorLogin = user.getExtendedUser().getCoordinador().getLogin();
this.coordinadorId = user.getExtendedUser().getCoordinador().getId();
this.coordinador = user.getExtendedUser().getCoordinador();
Hibernate.initialize(user.getExtendedUser().getAreas());
this.areas = user.getExtendedUser().getAreas();
Hibernate.initialize(user.getExtendedUser().getDesarrollos());
this.desarrollos = user.getExtendedUser().getDesarrollos();
public Long getId()
return id;
public void setId(Long id)
this.id = id;
public String getPuesto()
return puesto;
public void setPuesto(String puesto)
this.puesto = puesto;
public BigDecimal getSueldo()
return sueldo;
public void setSueldo(BigDecimal sueldo)
this.sueldo = sueldo;
public LocalDate getFechaIngreso()
return fechaIngreso;
public void setFechaIngreso(LocalDate fechaIngreso)
this.fechaIngreso = fechaIngreso;
public Long getUsuarioId()
return usuarioId;
public void setUsuarioId(Long userId)
this.usuarioId = userId;
/* public void setCoordinadorId(Long userId)
this.coordinadorId = userId;
public Long getCoordinadorId()
return coordinadorId;
*/
public User getCoordinador()
return coordinador;
public void setCoordinador(User user)
this.coordinador = user;
public Set<Area> getAreas()
return areas;
public void setAreas(Set<Area> areas)
this.areas = areas;
public Set<Desarrollo> getDesarrollos()
return desarrollos;
public void setDesarrollos(Set<Desarrollo> desarrollos)
this.desarrollos = desarrollos;
public Long getCoordinadorId()
return coordinadorId;
public void setCoordinadorId(Long userId)
this.coordinadorId = userId;
public String getCoordinadorLogin()
return coordinadorLogin;
public void setCoordinadorLogin(String userLogin)
this.coordinadorLogin = userLogin;
@Override
public boolean equals(Object o)
@Override
public int hashCode()
return Objects.hashCode(getId());
@Override
public String toString()
return "ExtendedUserDTO" +
"id=" + getId() +
", puesto='" + getPuesto() + "'" +
", sueldo=" + getSueldo() +
", fechaIngreso='" + getFechaIngreso() + "'" +
", usuario=" + getUsuarioId() +
", coordinador='" + getCoordinadorLogin() + "'" +
"";
Notes
- I'm really new on Angular, Java, and Jhipster.
- Please if I missed something important, let me know on the comment
and I will added to the question. - Im just trying to get only the ADMIN users so if you have a better
way I really would like to know
java spring postgresql jpa jhipster
1
You didn't post the stack trace of the exception, so we can only make guesses. My guess is that you're trying to serialize users as JSON, and that there is a bidirectional association betwee user and something else. So serializing a user serializes (for example) its authorities, which serializes the authorities user, which serializes its authorities, etc. etc.
– JB Nizet
Mar 22 at 20:01
@JBNizet hi I just added the stack trace I think the problem is a another entity I have, someone tell me I have to use@jsonignore
– Misael Landeros
Mar 22 at 20:12
1
You have a Usr which references an ExtendedUser, which references a User, etc. etc. And the exception explicitly says "Could not write JSON". So it's just what I suspected (and it's written right there in the exception message). Caredully use annotation to serialize what you actually want to serialize. Or better, IMHO, stop serializing your persistence model. Create DTOs that contain what you want to serialize and nothing else, and are thus designed to represent the response of your API.
– JB Nizet
Mar 22 at 20:16
@JBNizet thank you! i just start to learn all this and I trying to do in best way posible, the problem is in the DTO of ExtendedUser, I call user so that way I can see and update booth at the same time, so you think I should make a new DTO just for this?
– Misael Landeros
Mar 22 at 20:22
1
I think the persistence model should not be used as the external API responses. They're two related, but different things, each with their own, often contracitory constraints.
– JB Nizet
Mar 22 at 20:24
add a comment |
Overview
I'm learning Angular Java and JHipster, and I'm trying to filter the Users by Role but im getting a infinity recursion.
this is my userRepository.java
@Query(value = "select user from User user inner join user.authorities authorities where authorities.name =:role")
List<User> findByRole(@Param("role") String role);
I trying to do a inner join between the user table and the user_authority table, im parsing the role like a String "ROLE_ADMIN"
Upadte
Found something in the model if i do this select user.login
instead of select users
don't get the recursion error, so I think is maybe cause in the model is calling itself several times.
I have a relationship 1:1 with a another entity called extendedUser (for save additional information) and in extendedUser i have another relationship with user called coordinator so I think the model is calling itself.
This is just a part of the recursion in the console:
2019-03-22 14:08:32.082 WARN 12044 --- [ XNIO-2 task-9] .m.m.a.ExceptionHandlerExceptionResolver : Resolved exception caused by Handler execution: org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Infinite recursion (StackOverflowError); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Infinite recursion (StackOverflowError) (through reference chain:["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]
And this is my DTO on extended user when i think I have the problem
/**
* A DTO for the ExtendedUser entity.
*/
public class ExtendedUserDTO extends UserDTO implements Serializable
private final Logger log = LoggerFactory.getLogger(ExtendedUserDTO.class);
private Long id;
private String puesto;
private BigDecimal sueldo;
private LocalDate fechaIngreso;
private Long usuarioId;
//private Long coordinadorId;
private Set<Area> areas = new HashSet<>();
private Long coordinadorId;
private String coordinadorLogin;
private User coordinador;
private Set<Desarrollo> desarrollos = new HashSet<>();
public ExtendedUserDTO()
public ExtendedUserDTO(User user)
super(user);
this.puesto = user.getExtendedUser().getPuesto();
this.sueldo = user.getExtendedUser().getSueldo();
this.fechaIngreso = user.getExtendedUser().getFechaIngreso();
this.id = user.getId();
this.usuarioId = user.getId();
this.coordinadorLogin = user.getExtendedUser().getCoordinador().getLogin();
this.coordinadorId = user.getExtendedUser().getCoordinador().getId();
this.coordinador = user.getExtendedUser().getCoordinador();
Hibernate.initialize(user.getExtendedUser().getAreas());
this.areas = user.getExtendedUser().getAreas();
Hibernate.initialize(user.getExtendedUser().getDesarrollos());
this.desarrollos = user.getExtendedUser().getDesarrollos();
public Long getId()
return id;
public void setId(Long id)
this.id = id;
public String getPuesto()
return puesto;
public void setPuesto(String puesto)
this.puesto = puesto;
public BigDecimal getSueldo()
return sueldo;
public void setSueldo(BigDecimal sueldo)
this.sueldo = sueldo;
public LocalDate getFechaIngreso()
return fechaIngreso;
public void setFechaIngreso(LocalDate fechaIngreso)
this.fechaIngreso = fechaIngreso;
public Long getUsuarioId()
return usuarioId;
public void setUsuarioId(Long userId)
this.usuarioId = userId;
/* public void setCoordinadorId(Long userId)
this.coordinadorId = userId;
public Long getCoordinadorId()
return coordinadorId;
*/
public User getCoordinador()
return coordinador;
public void setCoordinador(User user)
this.coordinador = user;
public Set<Area> getAreas()
return areas;
public void setAreas(Set<Area> areas)
this.areas = areas;
public Set<Desarrollo> getDesarrollos()
return desarrollos;
public void setDesarrollos(Set<Desarrollo> desarrollos)
this.desarrollos = desarrollos;
public Long getCoordinadorId()
return coordinadorId;
public void setCoordinadorId(Long userId)
this.coordinadorId = userId;
public String getCoordinadorLogin()
return coordinadorLogin;
public void setCoordinadorLogin(String userLogin)
this.coordinadorLogin = userLogin;
@Override
public boolean equals(Object o)
@Override
public int hashCode()
return Objects.hashCode(getId());
@Override
public String toString()
return "ExtendedUserDTO" +
"id=" + getId() +
", puesto='" + getPuesto() + "'" +
", sueldo=" + getSueldo() +
", fechaIngreso='" + getFechaIngreso() + "'" +
", usuario=" + getUsuarioId() +
", coordinador='" + getCoordinadorLogin() + "'" +
"";
Notes
- I'm really new on Angular, Java, and Jhipster.
- Please if I missed something important, let me know on the comment
and I will added to the question. - Im just trying to get only the ADMIN users so if you have a better
way I really would like to know
java spring postgresql jpa jhipster
Overview
I'm learning Angular Java and JHipster, and I'm trying to filter the Users by Role but im getting a infinity recursion.
this is my userRepository.java
@Query(value = "select user from User user inner join user.authorities authorities where authorities.name =:role")
List<User> findByRole(@Param("role") String role);
I trying to do a inner join between the user table and the user_authority table, im parsing the role like a String "ROLE_ADMIN"
Upadte
Found something in the model if i do this select user.login
instead of select users
don't get the recursion error, so I think is maybe cause in the model is calling itself several times.
I have a relationship 1:1 with a another entity called extendedUser (for save additional information) and in extendedUser i have another relationship with user called coordinator so I think the model is calling itself.
This is just a part of the recursion in the console:
2019-03-22 14:08:32.082 WARN 12044 --- [ XNIO-2 task-9] .m.m.a.ExceptionHandlerExceptionResolver : Resolved exception caused by Handler execution: org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Infinite recursion (StackOverflowError); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Infinite recursion (StackOverflowError) (through reference chain:["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]->com.gits.sigem.domain.ExtendedUser["usuario"]->com.gits.sigem.domain.User["extendedUser"]
And this is my DTO on extended user when i think I have the problem
/**
* A DTO for the ExtendedUser entity.
*/
public class ExtendedUserDTO extends UserDTO implements Serializable
private final Logger log = LoggerFactory.getLogger(ExtendedUserDTO.class);
private Long id;
private String puesto;
private BigDecimal sueldo;
private LocalDate fechaIngreso;
private Long usuarioId;
//private Long coordinadorId;
private Set<Area> areas = new HashSet<>();
private Long coordinadorId;
private String coordinadorLogin;
private User coordinador;
private Set<Desarrollo> desarrollos = new HashSet<>();
public ExtendedUserDTO()
public ExtendedUserDTO(User user)
super(user);
this.puesto = user.getExtendedUser().getPuesto();
this.sueldo = user.getExtendedUser().getSueldo();
this.fechaIngreso = user.getExtendedUser().getFechaIngreso();
this.id = user.getId();
this.usuarioId = user.getId();
this.coordinadorLogin = user.getExtendedUser().getCoordinador().getLogin();
this.coordinadorId = user.getExtendedUser().getCoordinador().getId();
this.coordinador = user.getExtendedUser().getCoordinador();
Hibernate.initialize(user.getExtendedUser().getAreas());
this.areas = user.getExtendedUser().getAreas();
Hibernate.initialize(user.getExtendedUser().getDesarrollos());
this.desarrollos = user.getExtendedUser().getDesarrollos();
public Long getId()
return id;
public void setId(Long id)
this.id = id;
public String getPuesto()
return puesto;
public void setPuesto(String puesto)
this.puesto = puesto;
public BigDecimal getSueldo()
return sueldo;
public void setSueldo(BigDecimal sueldo)
this.sueldo = sueldo;
public LocalDate getFechaIngreso()
return fechaIngreso;
public void setFechaIngreso(LocalDate fechaIngreso)
this.fechaIngreso = fechaIngreso;
public Long getUsuarioId()
return usuarioId;
public void setUsuarioId(Long userId)
this.usuarioId = userId;
/* public void setCoordinadorId(Long userId)
this.coordinadorId = userId;
public Long getCoordinadorId()
return coordinadorId;
*/
public User getCoordinador()
return coordinador;
public void setCoordinador(User user)
this.coordinador = user;
public Set<Area> getAreas()
return areas;
public void setAreas(Set<Area> areas)
this.areas = areas;
public Set<Desarrollo> getDesarrollos()
return desarrollos;
public void setDesarrollos(Set<Desarrollo> desarrollos)
this.desarrollos = desarrollos;
public Long getCoordinadorId()
return coordinadorId;
public void setCoordinadorId(Long userId)
this.coordinadorId = userId;
public String getCoordinadorLogin()
return coordinadorLogin;
public void setCoordinadorLogin(String userLogin)
this.coordinadorLogin = userLogin;
@Override
public boolean equals(Object o)
@Override
public int hashCode()
return Objects.hashCode(getId());
@Override
public String toString()
return "ExtendedUserDTO" +
"id=" + getId() +
", puesto='" + getPuesto() + "'" +
", sueldo=" + getSueldo() +
", fechaIngreso='" + getFechaIngreso() + "'" +
", usuario=" + getUsuarioId() +
", coordinador='" + getCoordinadorLogin() + "'" +
"";
Notes
- I'm really new on Angular, Java, and Jhipster.
- Please if I missed something important, let me know on the comment
and I will added to the question. - Im just trying to get only the ADMIN users so if you have a better
way I really would like to know
java spring postgresql jpa jhipster
java spring postgresql jpa jhipster
edited Mar 22 at 20:20
Misael Landeros
asked Mar 22 at 5:04
Misael LanderosMisael Landeros
3910
3910
1
You didn't post the stack trace of the exception, so we can only make guesses. My guess is that you're trying to serialize users as JSON, and that there is a bidirectional association betwee user and something else. So serializing a user serializes (for example) its authorities, which serializes the authorities user, which serializes its authorities, etc. etc.
– JB Nizet
Mar 22 at 20:01
@JBNizet hi I just added the stack trace I think the problem is a another entity I have, someone tell me I have to use@jsonignore
– Misael Landeros
Mar 22 at 20:12
1
You have a Usr which references an ExtendedUser, which references a User, etc. etc. And the exception explicitly says "Could not write JSON". So it's just what I suspected (and it's written right there in the exception message). Caredully use annotation to serialize what you actually want to serialize. Or better, IMHO, stop serializing your persistence model. Create DTOs that contain what you want to serialize and nothing else, and are thus designed to represent the response of your API.
– JB Nizet
Mar 22 at 20:16
@JBNizet thank you! i just start to learn all this and I trying to do in best way posible, the problem is in the DTO of ExtendedUser, I call user so that way I can see and update booth at the same time, so you think I should make a new DTO just for this?
– Misael Landeros
Mar 22 at 20:22
1
I think the persistence model should not be used as the external API responses. They're two related, but different things, each with their own, often contracitory constraints.
– JB Nizet
Mar 22 at 20:24
add a comment |
1
You didn't post the stack trace of the exception, so we can only make guesses. My guess is that you're trying to serialize users as JSON, and that there is a bidirectional association betwee user and something else. So serializing a user serializes (for example) its authorities, which serializes the authorities user, which serializes its authorities, etc. etc.
– JB Nizet
Mar 22 at 20:01
@JBNizet hi I just added the stack trace I think the problem is a another entity I have, someone tell me I have to use@jsonignore
– Misael Landeros
Mar 22 at 20:12
1
You have a Usr which references an ExtendedUser, which references a User, etc. etc. And the exception explicitly says "Could not write JSON". So it's just what I suspected (and it's written right there in the exception message). Caredully use annotation to serialize what you actually want to serialize. Or better, IMHO, stop serializing your persistence model. Create DTOs that contain what you want to serialize and nothing else, and are thus designed to represent the response of your API.
– JB Nizet
Mar 22 at 20:16
@JBNizet thank you! i just start to learn all this and I trying to do in best way posible, the problem is in the DTO of ExtendedUser, I call user so that way I can see and update booth at the same time, so you think I should make a new DTO just for this?
– Misael Landeros
Mar 22 at 20:22
1
I think the persistence model should not be used as the external API responses. They're two related, but different things, each with their own, often contracitory constraints.
– JB Nizet
Mar 22 at 20:24
1
1
You didn't post the stack trace of the exception, so we can only make guesses. My guess is that you're trying to serialize users as JSON, and that there is a bidirectional association betwee user and something else. So serializing a user serializes (for example) its authorities, which serializes the authorities user, which serializes its authorities, etc. etc.
– JB Nizet
Mar 22 at 20:01
You didn't post the stack trace of the exception, so we can only make guesses. My guess is that you're trying to serialize users as JSON, and that there is a bidirectional association betwee user and something else. So serializing a user serializes (for example) its authorities, which serializes the authorities user, which serializes its authorities, etc. etc.
– JB Nizet
Mar 22 at 20:01
@JBNizet hi I just added the stack trace I think the problem is a another entity I have, someone tell me I have to use
@jsonignore
– Misael Landeros
Mar 22 at 20:12
@JBNizet hi I just added the stack trace I think the problem is a another entity I have, someone tell me I have to use
@jsonignore
– Misael Landeros
Mar 22 at 20:12
1
1
You have a Usr which references an ExtendedUser, which references a User, etc. etc. And the exception explicitly says "Could not write JSON". So it's just what I suspected (and it's written right there in the exception message). Caredully use annotation to serialize what you actually want to serialize. Or better, IMHO, stop serializing your persistence model. Create DTOs that contain what you want to serialize and nothing else, and are thus designed to represent the response of your API.
– JB Nizet
Mar 22 at 20:16
You have a Usr which references an ExtendedUser, which references a User, etc. etc. And the exception explicitly says "Could not write JSON". So it's just what I suspected (and it's written right there in the exception message). Caredully use annotation to serialize what you actually want to serialize. Or better, IMHO, stop serializing your persistence model. Create DTOs that contain what you want to serialize and nothing else, and are thus designed to represent the response of your API.
– JB Nizet
Mar 22 at 20:16
@JBNizet thank you! i just start to learn all this and I trying to do in best way posible, the problem is in the DTO of ExtendedUser, I call user so that way I can see and update booth at the same time, so you think I should make a new DTO just for this?
– Misael Landeros
Mar 22 at 20:22
@JBNizet thank you! i just start to learn all this and I trying to do in best way posible, the problem is in the DTO of ExtendedUser, I call user so that way I can see and update booth at the same time, so you think I should make a new DTO just for this?
– Misael Landeros
Mar 22 at 20:22
1
1
I think the persistence model should not be used as the external API responses. They're two related, but different things, each with their own, often contracitory constraints.
– JB Nizet
Mar 22 at 20:24
I think the persistence model should not be used as the external API responses. They're two related, but different things, each with their own, often contracitory constraints.
– JB Nizet
Mar 22 at 20:24
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55293202%2ffilter-user-by-role-cause-a-infinity-recursion%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55293202%2ffilter-user-by-role-cause-a-infinity-recursion%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
You didn't post the stack trace of the exception, so we can only make guesses. My guess is that you're trying to serialize users as JSON, and that there is a bidirectional association betwee user and something else. So serializing a user serializes (for example) its authorities, which serializes the authorities user, which serializes its authorities, etc. etc.
– JB Nizet
Mar 22 at 20:01
@JBNizet hi I just added the stack trace I think the problem is a another entity I have, someone tell me I have to use
@jsonignore
– Misael Landeros
Mar 22 at 20:12
1
You have a Usr which references an ExtendedUser, which references a User, etc. etc. And the exception explicitly says "Could not write JSON". So it's just what I suspected (and it's written right there in the exception message). Caredully use annotation to serialize what you actually want to serialize. Or better, IMHO, stop serializing your persistence model. Create DTOs that contain what you want to serialize and nothing else, and are thus designed to represent the response of your API.
– JB Nizet
Mar 22 at 20:16
@JBNizet thank you! i just start to learn all this and I trying to do in best way posible, the problem is in the DTO of ExtendedUser, I call user so that way I can see and update booth at the same time, so you think I should make a new DTO just for this?
– Misael Landeros
Mar 22 at 20:22
1
I think the persistence model should not be used as the external API responses. They're two related, but different things, each with their own, often contracitory constraints.
– JB Nizet
Mar 22 at 20:24