Criteria Hibernate - Error

Asked

Viewed 47 times

0

I’m getting the following Exception, I analyzed my code and I am not able to find the error.

The query is performed and returns the objects, but when returning, launches the Exception.

@SuppressWarnings("unchecked")
@Override
@Transactional(readOnly = true)
public List<RespostaRequerimento> consultar(ConsultarFilter filter) throws DAOException {
    Session session =  this.getEntityManager().unwrap(Session.class);

    Criteria criteria =  session.createCriteria(RespostaRequerimento.class);
    adicionarFiltro(filter, criteria);

    return criteria.list(); 
}

private void adicionarFiltro(ConsultarFilter filtro, Criteria criteria) {
    if(filtro !=null){
        if(!StringUtils.isEmpty(filtro.getUsuario())){
            criteria.add(Restrictions.like("usuario", filtro.getUsuario()));
        }
    }
}

java.lang.Nullpointerexception at Requerimentoserviceimpl.consultar(Consultationrequirementserviceimpl.java:102) at sun.reflect.Nativemethodaccessorimpl.invoke0(Native Method) at sun.reflect.Nativemethodaccessorimpl.invoke(Nativemethodaccessorimpl.java:39) at sun.reflect.Delegatingmethodaccessorimpl.invoke(Delegatingmethodaccessorimpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.aop.support.Aoputils.invokeJoinpointUsingReflection(Aoputils.java:302) at org.springframework.aop.framework.Jdkdynamicaopproxy.invoke(Jdkdynamicaopproxy.java:202) at $Proxy41.see (Unknown Source) at br.com.Experian.srv.answeranalysisoccurrence.core.service.ConsultRequesmentServiceTest.deveConsultarPortsUsuario(Consultationrequirementservicetest.java:194) at sun.reflect.Nativemethodaccessorimpl.invoke0(Native Method) at sun.reflect.Nativemethodaccessorimpl.invoke(Nativemethodaccessorimpl.java:39) at sun.reflect.Delegatingmethodaccessorimpl.invoke(Delegatingmethodaccessorimpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.junit.Runners.model.Frameworkmethod$1.runReflectiveCall(Frameworkmethod.java:47) at org.junit.Internal.runners.model.ReflectiveCallable.run(Reflectivecallable.java:12) at org.junit.Runners.model.Frameworkmethod.invokeExplosively(Frameworkmethod.java:44) at org.junit.Internal.runners.statements.InvokeMethod.evaluate(Invokemethod.java:17) at org.junit.Internal.runners.statements.RunBefores.evaluate(Runbefores.java:26) at org.springframework.test.context.junit4.statements.Runbeforetestmethodcallbacks.evaluate(Runbeforetestmethodcallbacks.java:75) at org.springframework.test.context.junit4.statements.Runaftertestmethodcallbacks.evaluate(Runaftertestmethodcallbacks.java:86) at org.springframework.test.context.junit4.statements.Springrepeat.evaluate(Springrepeat.java:84) at org.junit.Runners.ParentRunner.runLeaf(Parentrunner.java:271) at org.springframework.test.context.junit4.Springjunit4classrunner.runChild(Springjunit4classrunner.java:254) at org.springframework.test.context.junit4.Springjunit4classrunner.runChild(Springjunit4classrunner.java:89) at org.junit.Runners.Parentrunner$3.run(Parentrunner.java:238) at org.junit.Runners.Parentrunner$1.Chedule(Parentrunner.java:63) at org.junit.Runners.ParentRunner.runChildren(Parentrunner.java:236) at org.junit.Runners.ParentRunner.access$000(Parentrunner.java:53) at org.junit.Runners.Parentrunner$2.evaluate(Parentrunner.java:229) at org.springframework.test.context.junit4.statements.Runbeforetestclasscallbacks.evaluate(Runbeforetestclasscallbacks.java:61) at org.springframework.test.context.junit4.statements.Runaftertestclasscallbacks.evaluate(Runaftertestclasscallbacks.java:70) at org.junit.Runners.ParentRunner.run(Parentrunner.java:309) at org.springframework.test.context.junit4.Springjunit4classrunner.run(Springjunit4classrunner.java:193) at org.eclipse.Jdt.internal.junit4.runner.Junit4testreference.run(Junit4testreference.java:86) at org.eclipse.Jdt.internal.junit.runner.Testexecution.run(Testexecution.java:38) at org.eclipse.Jdt.internal.junit.runner.Remotetestrunner.runTests(Remotetestrunner.java:459) at org.eclipse.Jdt.internal.junit.runner.Remotetestrunner.runTests(Remotetestrunner.java:678) at org.eclipse.Jdt.internal.junit.runner.Remotetestrunner.run(Remotetestrunner.java:382) at org.eclipse.Jdt.internal.junit.runner.Remotetestrunner.main(Remotetestrunner.java:192)

  • What would be the code on line 102 of the class Query serviceimpl? .

  • Isaias thank you very much. The error was not in the criteria but in the convert that will treat the return. Ball show, vlw.

  • Vlw, Tiago, then mark the question as solved.

  • On this site we write "solved" on the question. If you have an answer that really helped you, mark it as accepted. If you came to the solution on your own, put in the solution as an answer. So content is more organized and easier to find in the future by other people with similar problems.

  • Diego good morning, how do I mark the answer as solution. What Isaias mentioned solved my problem.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.