我在 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();
关于java - 获取 org.hibernate.MappingException : No Dialect mapping for JDBC type: -4 exception?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12985533/