java – 获取org.hibernate.MappingException:没有JDBC类型的Dialect映射:-4 exception?

我在query.list()行中遇到以下异常:

org.hibernate.MappingException: No Dialect mapping for JDBC type: -4
    at org.hibernate.dialect.TypeNames.get(TypeNames.java:56)
    at org.hibernate.dialect.TypeNames.get(TypeNames.java:81)
    at org.hibernate.dialect.Dialect.getHibernateTypeName(Dialect.java:369)
    at org.hibernate.loader.custom.CustomLoader$Metadata.getHibernateType(CustomLoader.java:559)
    at org.hibernate.loader.custom.CustomLoader$ScalarResultColumnProcessor.performDiscovery(CustomLoader.java:485)
    at org.hibernate.loader.custom.CustomLoader.autoDiscoverTypes(CustomLoader.java:501)
    at org.hibernate.loader.Loader.getResultSet(Loader.java:1787)
    at org.hibernate.loader.Loader.doQuery(Loader.java:662)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
    at org.hibernate.loader.Loader.doList(Loader.java:2211)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2095)
    at org.hibernate.loader.Loader.list(Loader.java:2090)
    at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
    at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
    at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
    at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152)

以下是我的配置文件:

<property name="hibernate.connection.driver_resource">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.password">mysql</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/mydatabase</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.default_schema">mydatabase</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>

当我尝试将应用程序运行到Eclipse IDE中时,这个异常不会出现,但是当我创建jar应用程序并运行时,我只是得到它.
提前致谢…

解决方法:

有时,数据库会返回无法映射到Hibernate类型的奇怪类型的自定义SQL查询的结果(特别是在select下使用表达式时).

您需要查找违规查询并向其添加显式强制转换.

例如

Object o = session.createSQLQuery("select 2*2").uniqueResult();

可能会导致这样的问题.你可以修改如下:

Object o = session.createSQLQuery("select cast(2*2 as int)").uniqueResult();
上一篇:6.X elasticsearch实战学习笔记_索引管理07


下一篇:Maven項目打包報錯:Plugin execution not covered by lifecycle configuration