我尝试在Hibernate中Mappostgresql ltree列,如下所示:
所在实体:
private String path;
@Column(name="org_path", columnDefinition="ltree")
public String getPath() {
return path;
表格结构:
CREATE TABLE relationship (
relationship_id int4 NOT NULL,
parent_organization_id uuid NOT NULL,
child_organization_id uuid NOT NULL,
org_path ltree NOT NULL,
CONSTRAINT relationship_pk PRIMARY KEY (relationship_id),
CONSTRAINT organization_fk3 FOREIGN KEY (parent_organization_id) REFERENCES organization(organization_id) ON DELETE RESTRICT ON UPDATE RESTRICT,
CONSTRAINT organization_fk4 FOREIGN KEY (child_organization_id) REFERENCES organization(organization_id) ON DELETE RESTRICT ON UPDATE RESTRICT
)
出现以下错误:
wrong column type encountered in column [org_path] in table [relationship]; found [“schemaName"."ltree" (Types#OTHER)], but expecting [ltree (Types#VARCHAR)]
有人能帮助解决这个问题吗?
4条答案
按热度按时间0pizxfdo1#
在Java中实现一个自定义LTreeType类,如下所示:
并对Entity类进行如下注解:
5m1hhzi42#
直到我也创建了一个LQueryType,就像为LTreeType提供的类@ arnabbis一样,我的代码只知道字符串,但Postgres不知道如何使用字符串的ltree。
我的KotlinJPA是这样的:
dba5bblo3#
只需在@anarbbswas代码上添加此修改,它就会正常工作
jljoyd4f4#
在Hibernate 6.1.7.Final中,这不再起作用了。有关于如何迁移的建议吗?