I've developed a stored procedure to do some task in the DB which gets a custom type parameter.
DROP TYPE IF EXISTS custom_type CASCADE;
CREATE TYPE custom_type AS (
field1 integer,
field2 integer
);
CREATE OR REPLACE PROCEDURE my_proc(param1 custom_type) AS $$
BEGIN
-- DO NOTHING FOR NOW
END;
$$ LANGUAGE 'plpgsql';
in my java code I've created this custom type as a class and added connection to the procedure in my repository as followed..
@Data
public class CustomType {
int field1;
int field2;
public CustomType(Integer field1, Integer field2) {
this.field1 = field1;
this.field2 = field2;
}
}
public interface MyRepo extends RdbFilterQueryRepository<MyEntity> {
@Procedure(value = "my_proc")
void myProc(@Param("param1") CustomType myParam1);
}
When I call the procedure I get this error:
Caused by: java.lang.IllegalArgumentException: Cannot determine the bindable type for procedure parameter: null
I've tried many ways but nothing worked out. I've changed the custom type to a simple integer and it works.. I understand that it is connected to the parameter type and binding between the type in the DB to my class type. But I don't find a way to do it. What am I missing?
---UPDATE---
I've managed to make it work with a simple custom type (containing single field), by implementing UserType<T>
as a type converter, and registering it by another component implementation for TypeContributor
.
In our case the custom type has more than one field. So I've tried to implement the type converter CompositeUserType<T>
but sadly I don't manage to register it, because the TypeContributor
register function gets only UserType<T>
.
I've created a ticket in hibernate for it. They suggested a workaround using @CompositeTypeRegistration
but it does not work as well..