Java JDBC 类型没有方言映射:1111
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28192547/
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
No Dialect mapping for JDBC type: 1111
提问by SakeSushiBig
I'm working on a Spring JPA Application, using MySQL as database. I ensured that all spring-jpa libraries, hibernate and mysql-connector-java is loaded.
我正在开发一个 Spring JPA 应用程序,使用 MySQL 作为数据库。我确保所有 spring-jpa 库、hibernate 和 mysql-connector-java 都已加载。
I'm running a mysql 5 instance. Here is a excerpt of my application.properties file:
我正在运行一个 mysql 5 实例。这是我的 application.properties 文件的摘录:
spring.jpa.show-sql=false
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect
spring.datasource.url=jdbc:mysql://localhost/mydatabase
spring.datasource.username=myuser
spring.datasource.password=SUPERSECRET
spring.datasource.driverClassName=com.mysql.jdbc.Driver
When executing an integration test, spring startsup properly but fails on creating the hibernate SessionFactory, with the exception:
执行集成测试时,spring 正常启动,但无法创建休眠 SessionFactory,但异常:
org.hibernate.MappingException: No Dialect mapping for JDBC type: 1111
I think my dialects should be Mysql5Dialect, I also tried the one explicitly stating InnoDB, and the two dialect options which don't indicate the version 5. But I always end up with the same 'No Dialect mapping for JDBC type: 1111' message. My application.properties file resides in the test/resources source folder. It is recognized by the JUnit Test runner (I previously got an exception because of an typo in it).
我认为我的方言应该是 Mysql5Dialect,我也尝试了一个明确说明 InnoDB 的方言,以及两个不指示版本 5 的方言选项。但我总是得到相同的 'No Dialect mapping for JDBC type: 1111' 消息. 我的 application.properties 文件位于 test/resources 源文件夹中。它被 JUnit 测试运行程序识别(我之前因为输入错误而遇到异常)。
Are the properties I'm setting wrong? I couldn't find some official documentation on these property names but found a hint in this stackoverflow answer: https://stackoverflow.com/a/25941616/1735497
我设置的属性有误吗?我找不到关于这些属性名称的一些官方文档,但在这个 stackoverflow 答案中找到了一个提示:https: //stackoverflow.com/a/25941616/1735497
Looking forward for your answers, thanks!
期待您的解答,谢谢!
BTW The application is already using spring boot.
顺便说一句,该应用程序已经在使用 spring boot。
采纳答案by SakeSushiBig
Here the answer based on the comment from SubOptimal:
这里的答案基于来自 SubOptimal 的评论:
The error message actually says that one column type cannot be mapped to a database type by hibernate.
In my case it was the java.util.UUID
type I use as primary key in some of my entities. Just apply the annotation @Type(type="uuid-char")
(for postgres @Type(type="pg-uuid")
)
错误消息实际上是说一种列类型无法通过休眠映射到数据库类型。就我而言,它是java.util.UUID
我在某些实体中用作主键的类型。只需应用注释@Type(type="uuid-char")
(对于 postgres @Type(type="pg-uuid")
)
回答by icl7126
回答by Klapsa2503
Sometimes when you call sql procedure/function it might be required to return something. You can try returning void: RETURN;
or string (this one worked for me): RETURN 'OK'
有时,当您调用 sql 过程/函数时,可能需要返回某些内容。您可以尝试返回 void:RETURN;
或 string (这个对我有用):RETURN 'OK'
回答by jaskirat Singh
Please Check if some Column return many have unknow Typein Query .
请检查某些列是否返回许多未知的 Query类型。
eg : '1' as column_namecan have type unknown
例如:“1”作为 column_name可以具有类型未知
and 1 as column_name is Integeris correct One .
和1 作为 column_name 是 Integer是正确的 One 。
This thing worked for me.
这件事对我有用。
回答by Anubis
For anybody getting this error with an old hibernate (3.x) version:
对于使用旧的休眠 (3.x) 版本遇到此错误的任何人:
do not write the return type in capital letters. hibernate type implementation mapping uses lowercase return types and does not convert them:
不要用大写字母写返回类型。hibernate 类型实现映射使用小写返回类型并且不转换它们:
CREATE OR REPLACE FUNCTION do_something(param varchar)
RETURNS integer AS
$BODY$
...
回答by GaborH
In my case the problem was that, I forgot to add resultClasses attribute when I setup my stored procedure in my User class.
就我而言,问题是,当我在 User 类中设置存储过程时,我忘记添加 resultClasses 属性。
@NamedStoredProcedureQuery(name = "find_email",
procedureName = "find_email", resultClasses = User.class, //<--I forgot that.
parameters = {
@StoredProcedureParameter(mode = ParameterMode.IN, name = "param_email", type = String.class)
}),
回答by Ramya
I got the same error because my query returned a UUID column. To fix that I returned the UUID column as varchar type through the query like "cast(columnName as varchar)", then it worked.
我遇到了同样的错误,因为我的查询返回了一个 UUID 列。为了解决这个问题,我通过像“cast(columnName as varchar)”这样的查询将 UUID 列作为 varchar 类型返回,然后它就起作用了。
Example:
例子:
public interface StudRepository extends JpaRepository<Mark, UUID> {
@Modifying
@Query(value = "SELECT Cast(stuid as varchar) id, SUM(marks) as marks FROM studs where group by stuid", nativeQuery = true)
List<Student> findMarkGroupByStuid();
public static interface Student(){
private String getId();
private String getMarks();
}
}
回答by Mike Packer
This also happens when you are using Hibernate and returning a void function. AT least w/ postgres. It doesnt know how to handle the void. I ended up having to change my void to a return int.
当您使用 Hibernate 并返回 void 函数时,也会发生这种情况。至少带有 postgres。它不知道如何处理虚空。我最终不得不将 void 更改为 return int。
回答by tutak
If you are using Postgres, check that you don't have a column of type Abstime. Abstime is an internal Postgres datatype not recognized by JPA. In this case, converting to Text using TO_CHARcouldhelp if permitted by your business requirements.
如果您使用 Postgres,请检查您是否没有Abstime类型的列。Abstime 是 JPA 无法识别的内部 Postgres 数据类型。在这种情况下,如果您的业务需求允许,使用TO_CHAR转换为文本可能会有所帮助。
回答by Bharti Rawat
If you have native SQL query then fix it by adding a cast to the query.
如果您有本机 SQL 查询,则通过向查询添加强制转换来修复它。
Example:
示例:
CAST('yourString' AS varchar(50)) as anyColumnName
In my case it worked for me.
就我而言,它对我有用。