获得org.hibernate.MappingException:没有方言映射JDBC类型:-4异常

2019-07-01 10:49发布

我在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那么这个例外不来了,但是当我创建应用程序的罐子,然后运行只有我得到它。 提前致谢...

Answer 1:

有时奇怪类型的自定义SQL查询不能映射到Hibernate类型(特别是当你使用下表达式的数据库返回结果select )。

你需要找到一个问题的查询,并添加显式转换到它。

例如

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

可能会引起这样的问题。 您可以按如下修正:

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


Answer 2:

得到了解决:

只是改变了查询,我取整的记录,而不是选择特定的。 从表中 ,然后得到相应的字段(此处为脚本)从表对象的值,而不是使用选择脚本表例如,现在是工作的罚款。



文章来源: Getting org.hibernate.MappingException: No Dialect mapping for JDBC type: -4 exception?