java 获取 org.hibernate.MappingException:没有 JDBC 类型的方言映射:-4 异常?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12985533/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting org.hibernate.MappingException: No Dialect mapping for JDBC type: -4 exception?
提问by milind_db
I am getting following exception at query.list()line:
我在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)
following is my configuration file:
以下是我的配置文件:
<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>
When I am trying to run application into Eclipse IDE then this exception is not coming but when I create jar of application and run then only I am getting it. thanks in advance...
当我尝试将应用程序运行到 Eclipse IDE 中时,此异常不会出现,但是当我创建应用程序 jar 并运行时,只有我得到它。提前致谢...
采纳答案by milind_db
Got the solution:
得到了解决方案:
Just change the Query, I am fetching whole record instead of select specific. e.g. from tableand then get respective field (here script) value from table Object instead of using select script from table, It is working fine now.
只需更改查询,我正在获取整个记录而不是特定的选择。例如从表然后从表对象中获取相应的字段(此处为脚本)值,而不是使用表中的选择脚本,现在工作正常。
回答by axtavt
Sometimes database returns results of custom SQL queries in strange types that cannot be mapped to Hibernate types (especially when you use expressions under select
).
有时数据库会以无法映射到 Hibernate 类型的奇怪类型返回自定义 SQL 查询的结果(尤其是当您在 下使用表达式时select
)。
You need to find an offending query and add an explicit cast to it.
您需要找到有问题的查询并向其添加显式转换。
For example
例如
Object o = session.createSQLQuery("select 2*2").uniqueResult();
may cause such a problem. You may fix it as follows:
可能会导致这样的问题。您可以按如下方式修复它:
Object o = session.createSQLQuery("select cast(2*2 as int)").uniqueResult();