hypersistence-utils icon indicating copy to clipboard operation
hypersistence-utils copied to clipboard

Add support of PostgreSQL types in PostgreSQL array

Open arturmkr opened this issue 3 years ago • 4 comments

For example, there is a following DTO in PostgreSQL:

create table email
(
    account_id varchar(100),
    id varchar(100),
    recipients recipient[],
    subject varchar(100),
    content varchar(100)
);
create type recipient as
(
    email text,
    name  text
);

There is an option to use PostgreSQL array: https://vladmihalcea.com/postgresql-array-java-list/

But there is no option to use in PostgreSQL array custom types.

With Regards

arturmkr avatar Apr 11 '21 11:04 arturmkr

I've never used custom PostgreSQL Types. If you figure out how to do it, send me a Pull Request, and I'll review it when I have some time.

vladmihalcea avatar Apr 11 '21 12:04 vladmihalcea

I am not so good at Hibernate to make PR to fix it.

But using plain SQL it works in a following way: INSERT INTO public.email (account_id, id, recipients, subject, content) VALUES ('qwerty', 'aa12345', '{([email protected],"frank"),([email protected],"john")}', 'mysubject', 'mycontent');

arturmkr avatar Apr 12 '21 05:04 arturmkr

That's a good start. Now, you need to check out how to fo that with a JDBC PreparedStatement and send that with a bind parameter value.

vladmihalcea avatar Apr 12 '21 12:04 vladmihalcea

This would be much easier to implement if pgjdbc had support for structs. Unfortunately they abandoned the idea for probably the same reasons this should not be implemented as part of hibernate-types: https://github.com/pgjdbc/pgjdbc/issues/381.

jwgmeligmeyling avatar Jun 22 '21 09:06 jwgmeligmeyling