I define a type T
and a view V
in a PostgreSQL database.
CREATE TYPE my_type AS
(
mt_column1 smallint NOT NULL
);
CREATE VIEW my_view
AS SELECT
some_column_id integer
ARRAY(SELECT
ROW(an_int)::my_type
FROM a_table
) AS my_view_types
FROM a_regular_table
WHERE my_condition_hold);
Using the code generation on release 3.7 I get both an UDT record class MyTypeRecord
and a table record class MyViewRecord
and the UDT POJO class MyType
and table POJO class MyView
.
The MyView
generated class has an array of MyTypeRecord
.
public class MyView extends Object implements Serializable, Cloneable, IMyView {
private static final long serialVersionUID = 1984808170;
private final Long some_column_id;
private final MyTypeRecord[] my_view_types;
}
while in a POJO I would expect an array of POJOs, e.g.:
private final MyType[] my_view_types;
Another interesting fact is that the pojo and the record for the type are in the udt
folder, while for the view they are in the tables
folder: maybe this can help to find a solution/explanation.
Is there a way to make the View
a pojo-only conversion at generation time?
Upon request, I attached a working example that generates the records and POJOs as I described. It is shared with FileDropper at this link.
I also report one possible trick to avoid this issue, to be used iff you are really desperate. As reported in this stackoverflow question/answer, jOOQ even if we assign a POJO instead of the record, will not be able to automatically convert the array of records into the record class MyTypeRecord
. Hence, you can parse the array of ROW
s to json using function array_to_json
. In my example would be:
CREATE VIEW my_view
AS SELECT
some_column_id integer
array_to_json(ARRAY(SELECT
ROW(an_int)::my_type
FROM a_table
))::json AS my_view_types
FROM a_regular_table
WHERE my_condition_hold);
This should be converted automatically by jOOQ to a JSON if you register this binding.