当前位置: 首页 > 面试题库 >

org.hibernate.HibernateException:无法实例化resultclass

张坚白
2023-03-14
问题内容

完整堆栈跟踪:

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)

第11行指向此查询的最后一行:

        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));

这是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;
    }
}

构造函数在里面,为什么它不起作用?注意:我也在使用Spring,这是一个DTO bean。

我在这里想念什么?


问题答案:

的无参数构造函数EmployeeScore应为public:

public EmployeeScore(){}


 类似资料:
  • 问题内容: 我正在使用Hibernate框架开发Web应用程序。尝试运行webapp时出现此错误。 错误控制台: 我的映射文件(hbm.xml): DataAccessObject文件代码: 在上面的代码中,抛出了异常-在catch中的字符串显示在控制台的错误中。 这是我的bean或POJO文件: 我检查了其他线程解决方案。 我已包含文件 所有的setter和getter都没有错别字。 我也有。

  • 我试图使用Postgis 2.2和Postgreql 9.5与JPA,Postgis 9.5方言。我已经在pom.xml的要求,按这里http://www.hibernatespatial.org/documentation/documentation/和类型导入正确,但是当我试图运行程序使用几何类型我得到这个错误: 我显然遗漏了一些配置,有人能指出是什么吗?

  • 我在MapFragment的布局文件中出现了这个错误 我试过了 > 安装Google Play服务,但仍有错误 - com.google.android.gms.maps.MapFragment(开放类,显示异常,清除缓存) 提示:在自定义视图中使用view.isinEditMode()跳过代码或在IDE中显示示例数据。 如果这是一个意外错误,您也可以尝试构建项目,然后手动刷新布局。 异常详细信息

  • 我正在将一个Java EE应用程序部署到Bluemix,当第一个请求到达时,我得到了这个错误: 2015-05-20T23:11:58.51+0200[app/0]OUT[INFO]FFDC1015I:已创建FFDC事件:“java.util.ServiceConfigurationError:javax.servlet.ServletContainerInitializer:Provider o

  • 我正在尝试将H2设置为内存数据库。我已将其配置为: 然而,当我尝试运行它时,我会遇到这个错误 我不确定它为什么不接受jdbc url,我的confg格式有什么问题吗?