2012-08-09 13 views
12

completo seguimiento de la pila:org.hibernate.HibernateException: No se pudo crear una instancia de clase de resultado

org.hibernate.HibernateException: Could not instantiate resultclass: com.firstbankpr.lmu.data.dto.EmployeeScore 
at org.hibernate.transform.AliasToBeanResultTransformer.transformTuple(AliasToBeanResultTransformer.java:99) 
at org.hibernate.hql.HolderInstantiator.instantiate(HolderInstantiator.java:96) 
at org.hibernate.loader.custom.CustomLoader.getResultList(CustomLoader.java:361) 
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276) 
at org.hibernate.loader.Loader.list(Loader.java:2271) 
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:316) 
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1842) 
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:165) 
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:157) 
at com.nimchip.lmu.data.dao.hibernate.WinnerHibernateDAO.findEmployeeTotals(WinnerHibernateDAO.java:155) 
at com.nimchip.lmu.data.dao.WinnerDAOTest.testEmpScore(WinnerDAOTest.java:159) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) 
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) 
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) 
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) 
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74) 
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83) 
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72) 
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231) 
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49) 
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) 
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) 
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) 
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) 
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) 
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) 
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71) 
at org.junit.runners.ParentRunner.run(ParentRunner.java:236) 
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174) 
at org.junit.runner.JUnitCore.run(JUnitCore.java:157) 
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:71) 
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:199) 
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:62) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120) 

Línea 11 puntos a la última línea de esta consulta:

 Query query = currentSession().createSQLQuery(
      "select n.EMP_ID as id, SUM(DISTINCT(nom.TOTAL_POINT)) as score from" + 
        " NOMINEE n join NOMINATION nom on nom.NOM_ID = n.NOM_ID" + 
        " join EMPLOYEE e on n.EMP_ID = e.EMP_ID" + 
        " join COMPANY c on c.COMPANY_CODE = e.COMPANY_CODE" + 
        " join REGION r on r.REGION_ID = c.REGION_ID" + 
        " where nom.PERIOD_ID = :periodId" + 
        " AND nom.STATUS_ID = 2" + 
        " AND e.ISACTIVE = 1" + 
        " AND nom.CATEGORY_CODE != 'H'" + 
        " AND r.REGION_ID = :regionId" + 
        " group by n.EMP_ID") 
      .addScalar("id") 
      .addScalar("score") 
      .setParameter("regionId", regionId) 
      .setParameter("periodId", periodId) 
      .setResultTransformer(Transformers.aliasToBean(EmployeeScore.class)); 

Aquí está la EmployeeScore.class:

public class EmployeeScore { 

    private int id; 
    private int score; 

    EmployeeScore(){} 

    public EmployeeScore(int id, int score) { 
     this.id = id; 
     this.score = score; 
    } 

    public int getId() { 
     return id; 
    } 

    public void setId(int id) { 
     this.id = id; 
    } 

    public int getScore() { 
     return score; 
    } 

    public void setScore(int score) { 
     this.score = score; 
    } 

    @Override 
    public boolean equals(Object o) { 
     if (this == o) return true; 
     if (o == null || getClass() != o.getClass()) return false; 

     EmployeeScore that = (EmployeeScore) o; 

     if (id != that.id) return false; 
     if (score != that.score) return false; 

     return true; 
    } 

    @Override 
    public int hashCode() { 
     int result = id; 
     result = 31 * result + score; 
     return result; 
    } 
} 

constructores están en, por qué no está funcionando? Nota: También estoy usando Spring y este es un bean DTO.

¿Qué me falta aquí?

Respuesta

34

El constructor sin argumentos de EmployeeScore debe ser pública:

public EmployeeScore(){} 
+6

Jesucristo odio estos momentos de auto-facepalm. Gracias. – Nimchip

+0

Gracias, yo no añade constructor sin argumentos – Maciej

7

Otra razón que podría obtener este error se debe a que es una clase interna que está tratando de transformar, el código se compila, pero se obtiene este mismo error

+2

En el caso de un varón de clase interna es estática y pública (Ver http://stackoverflow.com/a/24437418/874502) – denispyr

Cuestiones relacionadas