postgresql JDBC 类型没有方言映射:2003
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21630370/
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: 2003
提问by Vikas Singh
Though there are some question exists with this title , but my query does not solve from those thread.
虽然这个标题存在一些问题,但我的查询没有从这些线程中解决。
I am executing recursive (using with clause) query through hibernate in postgres, query's result contains path of search also
我在 postgres 中通过 hibernate 执行递归(使用 with 子句)查询,查询的结果也包含搜索路径
ex: one row of query result
例如:一行查询结果
5811;"axyz_3_3";"ABC";5782;5811;5797;4;"**{acl_3_3,acl3_4,acl3,acl_3_3}**";t;t
Does hibernate has any mapping type for "{acl_3_3,acl3_4,acl3,acl_3_3}"
other than String,
something similar to CHARACTER_ARRAY
or CHAR_ARRAY
.
hibernate 是否有"{acl_3_3,acl3_4,acl3,acl_3_3}"
除 String 之外的任何映射类型,类似于CHARACTER_ARRAY
或CHAR_ARRAY
。
Below is the sample of the query's output
以下是查询输出的示例
id |name|discri|pId|asscID|immeId|depth|path|cycle|canDelete
5797;"abc3";"abc";5782;5811;5788;7;"{abc_3_3,abc3_4,abc3,abc4}";t;f
5797;"abc3";"abc";5782;5786;5813;6;"{abc1,abc2,abc3,abc3}";t;f
5799;"abc4";"abc";5782;5811;5786;6;"{abc_3_3,abc3_4,abc4}";t;f
5788;"abc2";"abc";5782;5811;5786;6;"{abc_3_3,abc3_4,abc2}";f;f
5786;"abc1";"abc";5782;5786;5799;5;"{abc1,abc2,abc3,abc1}";t;f
5797;"abc3";"abc";5782;5786;5813;5;"{abc1,abc2,abc3,abc3}";t;f
5813;"abc3_4";"abc";5782;5786;5811;5;"{abc1,abc2,abc3_4}";f;f
5786;"abc1";"abc";5782;5811;5799;5;"{abc_3_3,abc4,abc1}";f;f
5813;"abc3_4";"abc";5782;5811;5797;4;"{abc3_4,abc3,abc3_4}";t;f
5811;"abc_3_3";"abc";5782;5811;5797;4;"{abc_3_3,abc3,abc_3_3}";t;t
5799;"abc4";"abc";5782;5811;5797;4;"{abc3,abc4}";f;f
Hibernate is throwing below exception
Hibernate 抛出以下异常
Caused by: com.vik.prod.service.UnidentifiedException: No Dialect mapping for JDBC type: 2003
at com.vik.prod.service.ServiceExecutorUtils.execute(ServiceExecutorUtils.java:93)
at com.vik.prod.service.ServerServiceExecutor.execute(ServerServiceExecutor.java:76)
at com.vik.prod.service.ClientDelegate.execute(ClientDelegate.java:197)
... 33 more
Caused by: org.hibernate.MappingException: No Dialect mapping for JDBC type: 2003
引起:org.hibernate.MappingException:JDBC 类型没有方言映射:2003
采纳答案by Vikas Singh
Hibernate does not provide and Converter class/Mapper class to convert DB text[] datatype, For this either we can write our own converted type implementing UserTypeor we using sqlQuery.addScalar( "path", Hibernate.TEXT ); we can map text[] to text and then in java code we can split it from ','
Hibernate 没有提供 Converter 类/Mapper 类来转换 DB text[] 数据类型,为此我们可以编写自己的转换类型实现UserType或者我们使用 sqlQuery.addScalar( "path", Hibernate.TEXT ); 我们可以将 text[] 映射到文本,然后在 Java 代码中我们可以将它从 ',' 拆分
回答by 42n4
Use a package 'com.vladmihalcea:hibernate-types-52:2.8.0' or add your database dialect to yml file in resources:
使用包 'com.vladmihalcea:hibernate-types-52:2.8.0' 或将您的数据库方言添加到资源中的 yml 文件:
@Entity
@TypeDefs({
@TypeDef(name = "string-array", typeClass = StringArrayType.class),
@TypeDef(name = "json", typeClass = JsonStringType.class),
@TypeDef(name = "jsonb", typeClass = JsonBinaryType.class)
})
public class Post implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Type(type = "string-array")
@Column(columnDefinition = "text[]")
private String[] tags;