Caused by: org.hibernate.QueryException: Could not resolve requested type for CAST : INT

懵懂的女人 提交于 2020-07-09 11:55:06

问题


Caused by: org.hibernate.QueryException: Could not resolve requested type for CAST : INT [ SELECT SUBSTRING(referenceComptable , 8, 14) AS seqNum, SUBSTRING(referenceComptable, 4,7) AS yearCegid, SUBSTRING(referenceComptable, 1,3) AS journal FROM com.dso.model.comptabilite.cegid.EtapeJudiciaireLnkFactureActesHonoraires WHERE dateCegidGenerated BETWEEN :date AND :dateYearIntervalDate ORDER BY CAST(seqNum AS INT), CAST(yearCegid AS INT), CAST(journal AS INT) ASC ]

HQL QUery: public ScrollableResults retrieveSequenceNumberForCegidGenerated(){

        StringBuilder queryBuilder = new StringBuilder(" SELECT SUBSTRING(referenceComptable , 8, 14) AS seqNum, SUBSTRING(referenceComptable, 4,7) AS yearCegid, SUBSTRING(referenceComptable, 1,3) AS journal")
                            .append(" FROM EtapeJudiciaireLnkFactureActesHonoraires ")
                            .append(" WHERE dateCegidGenerated BETWEEN :date AND :dateYearIntervalDate ")
                            .append(" ORDER BY CAST(seqNum AS INT), CAST(yearCegid AS INT), CAST(journal AS INT) ASC ");

        Query query = getFilteredCurrentSession().createQuery(queryBuilder.toString());

        //SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
        Date date = new Date();

        LocalDate yearIntervalDate = LocalDate.now().minusDays(365);
        Date dateYearIntervalDate = Date.from(yearIntervalDate.atStartOfDay(ZoneId.systemDefault()).toInstant());

        query.setParameter("date", date);
        query.setParameter("dateYearIntervalDate", dateYearIntervalDate);

        ScrollableResults referenceComptable = query.scroll(ScrollMode.FORWARD_ONLY);
        query.setCacheMode(CacheMode.IGNORE)
             .setFetchSize(500);

        return referenceComptable;
    }

When i tried to CAST as INT it didn'y work also. What can be done to cast it ffrom string to integer?

Stack Trace

Caused by: org.hibernate.QueryException: Could not resolve requested type for CAST : INTEGER [ SELECT SUBSTRING(referenceComptable , 8, 7) AS seqNum, SUBSTRING(referenceComptable, 4,4) AS yearCegid, SUBSTRING(referenceComptable, 1,3) AS journal FROM com.dso.model.comptabilite.cegid.EtapeJudiciaireLnkFactureActesHonoraires WHERE dateCegidGenerated BETWEEN :date AND :dateYearIntervalDate ORDER BY CAST(SUBSTRING(referenceComptable , 8, 14) AS INTEGER), CAST(SUBSTRING(referenceComptable, 4,7) AS INTEGER), journal ASC ] at org.hibernate.QueryException.generateQueryException(QueryException.java:120) ~[hibernate-core-5.0.2.Final.jar:5.0.2.Final] at org.hibernate.QueryException.wrapWithQueryString(QueryException.java:103) ~[hibernate-core-5.0.2.Final.jar:5.0.2.Final] at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:218) ~[hibernate-core-5.0.2.Final.jar:5.0.2.Final] at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:142) ~[hibernate-core-5.0.2.Final.jar:5.0.2.Final] at org.hibernate.engine.query.spi.HQLQueryPlan.(HQLQueryPlan.java:115) ~[hibernate-core-5.0.2.Final.jar:5.0.2.Final] at org.hibernate.engine.query.spi.HQLQueryPlan.(HQLQueryPlan.java:76) ~[hibernate-core-5.0.2.Final.jar:5.0.2.Final] at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:150) ~[hibernate-core-5.0.2.Final.jar:5.0.2.Final] at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:298) ~[hibernate-core-5.0.2.Final.jar:5.0.2.Final] at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:236) ~[hibernate-core-5.0.2.Final.jar:5.0.2.Final] at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1825) ~[hibernate-core-5.0.2.Final.jar:5.0.2.Final] at com.dso.dao.comptabilite.cegid.impl.ReferenceComptableSequenceDAOImpl.retrieveSequenceNumberForCegidGenerated

来源:https://stackoverflow.com/questions/52201728/caused-by-org-hibernate-queryexception-could-not-resolve-requested-type-for-ca

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!