I am trying to map postgresql ltree column in hibernate as follows:
In entity :
private String path;
@Column(name="org_path", columnDefinition="ltree")
public String getPath() {
return path;
Table structure:
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
)
Getting the following error:
wrong column type encountered in column [org_path] in table [relationship]; found [“schemaName"."ltree" (Types#OTHER)], but expecting [ltree (Types#VARCHAR)]
Can anyone help how to resolve this issue?
just add this modifications on @anarbbswas code and then it will work fine
Implement a custom LTreeType class in Java as follows:
And annotate the Entity class as follows:
I had fits until I also created an LQueryType just like the class @arnabbiswas provided for LTreeType. My code only knows about Strings, but Postgres does not know how to use ltree with Strings. The types and operations are:
So my Kotlin JPA is like this: