hypersistence-utils
hypersistence-utils copied to clipboard
Add support of PostgreSQL types in PostgreSQL array
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
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.
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');
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.
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.