正在获取 org.hibernate.MappingException:JDBC 类型没有方言映射:-8 异常

Getting org.hibernate.MappingException: No Dialect mapping for JDBC type: -8 exception

我正在尝试通过 SQLQuery.list() 执行以下本机查询:

    SELECT Report.ROWID, Rpt.REPORT_NAME
     FROM REPORT Report, RPT Rpt
     WHERE Report.RPT_ID = Rpt.RPT_ID AND Rpt.USER_ID <> (SELECT USER_ID FROM USER WHERE LOGIN_ID = 'SYSTEM') 
AND Report.CON_ID = :1 AND Report.IMPLEMENTATION_PHASE = :2 AND Report.AIR_INTERFACE = :3 
AND Report.DATE_PSAP_REQUEST_WITHDRAWN IS NOT NULL 
AND Report.UPLOAD_DATE = (SELECT MAX(UPLOAD_DATE) FROM REPORT frs, RPT fr where frs.fcc_rpt_id = fr.fcc_rpt_id and fr.user_id <> (SELECT USER_ID FROM NEO_USER WHERE LOGIN_ID = 'SYSTEM'));

我的 hibernate-cfg.xml 文件配置为,

<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="connection.url">jdbc:oracle:thin:@localhost:1521:mydatabase</property>
        <property name="connection.username">root</property>
        <property name="connection.password">mydatabase</property>
        
        <property name="connection.autocommit">false</property>

        
        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>

但它没有执行,它在日志中出现如下错误:

org.hibernate.MappingException: No Dialect mapping for JDBC type: -8
    at org.hibernate.dialect.TypeNames.get(TypeNames.java:87)
    at org.hibernate.dialect.TypeNames.get(TypeNames.java:118)
    at org.hibernate.dialect.Dialect.getHibernateTypeName(Dialect.java:653)
    at org.hibernate.loader.custom.JdbcResultMetadata.getHibernateType(JdbcResultMetadata.java:93)
    at org.hibernate.loader.custom.ScalarResultColumnProcessor.performDiscovery(ScalarResultColumnProcessor.java:62)
    at org.hibernate.loader.custom.CustomLoader.autoDiscoverTypes(CustomLoader.java:498)
    at org.hibernate.loader.Loader.getResultSet(Loader.java:2074)
    at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1863)
    at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1839)
    at org.hibernate.loader.Loader.doQuery(Loader.java:910)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:355)
    at org.hibernate.loader.Loader.doList(Loader.java:2554)
    at org.hibernate.loader.Loader.doList(Loader.java:2540)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2370)
    at org.hibernate.loader.Loader.list(Loader.java:2365)
    at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:353)
    at org.hibernate.internal.SessionImpl.listCustomQuery(SessionImpl.java:1909)
    at org.hibernate.internal.AbstractSessionImpl.list(AbstractSessionImpl.java:311)
    at org.hibernate.internal.SQLQueryImpl.list(SQLQueryImpl.java:141)
    at com.sprint.neo.querymodel.dao.QueryModelDAO.executeSqlQuery(QueryModelDAO.java:307)
    at com.sprint.neo.querymodel.common.QueryObjectCache.executeQuery(QueryObjectCache.java:126)
    at com.sprint.neo.e911.types.projecttypes.TMO_NG911ProjectType.validateOnFccReport(TMO_NG911ProjectType.java:77)
    at com.sprint.neo.querymodel.common.QueryApplication.checkPsapPhaseOnFccReport(QueryApplication.java:2249)
    at com.sprint.neo.querymodel.common.QueryApplication.pspAddPsap(QueryApplication.java:2450)
    at com.sprint.neo.e911.util.prj.MassProjectCreateUtil.addPsap(MassProjectCreateUtil.java:215)
    at com.sprint.neo.e911.util.prj.MassProjectCreateUtil.createProject(MassProjectCreateUtil.java:161)
    at com.sprint.neo.e911.util.prj.BaseMassProjectCreateHandler.validateAndAddProjects(BaseMassProjectCreateHandler.java:33)
    at com.sprint.neo.e911.util.prj.MassProjectCreateApi.validateAndAddProjects(MassProjectCreateApi.java:123)
    at com.sprint.neo.engine.controller.actions.MassProjCreateAction.doExecute(MassProjCreateAction.java:74)
    at com.sprint.neo.bc4j.controller.actions.NeoAction.execute(NeoAction.java:34)
    at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:425)
    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:228)
    at com.sprint.neo.bc4j.controller.NeoRequestProcessor.process(NeoRequestProcessor.java:77)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
    at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:526)
    at org.apache.catalina.valves.RequestFilterValve.process(RequestFilterValve.java:348)
    at org.apache.catalina.valves.RemoteAddrValve.invoke(RemoteAddrValve.java:53)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:678)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:861)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1579)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.base/java.lang.Thread.run(Thread.java:830)

你能给我解决这个错误的方法吗? 我得到的建议很少

但这些对我的情况没有帮助。

查询编辑的其中一列 return 是 ROWID

我认为这是导致问题的查询:

SELECT FccReportSave.ROWID ...

以下是三种可能的解决方案:

选项 1:不要 return ROWID

选项 2:创建自定义方言

您可以创建一个自定义方言来告诉 Hibernate ORM how to convert the ROWID to a Java type

我不确定如何在 Java 中表示 ROWID,也许 String 会起作用:

package my.project;

public class OracleCustomDialect extends Oracle10gDialect {
  
    public OracleCustomDialect() {
        this.registerHibernateType( java.sql.Types.ROWID, org.hibernate.type.StandardBasicTypes.STRING );
    }
}

然后你可以通过设置 属性 hibernate.dialect:

来使用这个方言
<property name="hibernate.dialect">my.project.OracleCustomDialect</property>

您也可以创建一个 custom type 而不是使用 StandardBasicTypes.STRING ,这样您就可以将其转换为您想要的任何内容。

选项 3:添加标量

sess.createSQLQuery("SELECT FccReportSave.ROWID ...")
 .addScalar("FccReportSave.ROWID", StandardBasicTypes.STRING)
 .getResultList();