why does this error come out java.lang.StackOverflowError?

0

I have the following query

@NamedQuery(name = "findNivelesPersonaByCvePersona", query= "select myNivelesPersona from NivelesPersona myNivelesPersona where myNivelesPersona.persona.cveIdPersona = ?1"),

and the following in the service class

 public List<NivelesPersona> findByCveIdPersona(int cveIdPersona);
 
 y en la clase Impl
 
 @Override
    public List<NivelesPersona> findByCveIdPersona(int cveIdPersona) {
        return new java.util.ArrayList<NivelesPersona>(nivelesPersonaDAO.findByCveIdPersona(cveIdPersona));
    }

and in the DAO

 public Set<NivelesPersona> findByCveIdPersona(int cveIdPersona);
 
 
 Y DAO Impl
 
 @Override
    public Set<NivelesPersona> findByCveIdPersona(int cveIdPersona) {
        return findByCveIdPersona(cveIdPersona);
    }

and in the class where I send him to call

person = personaService.findPersonaByPrimaryKey(1);
        cvePersona = person.getCveIdPersona();
     
       
         System.out.println("pruebaaaaaa" +nivelesPersonaService.findByCveIdPersona(cvePersona));

and raise but that error comes out and mark it on the Impl DAO in the return

why?

    
asked by Root93 08.02.2018 в 23:29
source

1 answer

0

Each time a method call is made, a space of a memory area called stack is used. If you make so many calls to methods that the space ends, you have a stack overflow .

Usually, the cause of this is infinite recursion . A method that when executed calls itself (directly, or by calling other methods that then call the original method) without ever leaving. Looking at the stacktrace of the exception, usually 1 you will see a huge list of calls to methods that repeat cyclically from a list.

And you have:

@Override
public Set<NivelesPersona> findByCveIdPersona(int cveIdPersona) {
    return findByCveIdPersona(cveIdPersona);
}

PS: You have more errors apart from this one, but since you do not add the stacktrace it is impossible to check if this is the method that causes the problem. But hey, now you know what to look for.

1 In theory, you might have 99% of the stack occupied by infinite recursion of a thread and that just the call that "causes" that there is no more memory is from another method that has nothing to do with it. But I have not seen what ever happened.     
answered by 08.02.2018 в 23:45