I'm making a custom Hibernate type using AbstractSingleColumnStandardBasicType
to automatically convert the SQL UDT into a Java type. The SQL uses database functions to construct and serialize the column data from BLOBs and/or CLOBs, and I want to hide that from a user. So they don't have to use @ColumnTransformer(read="_serializer(column_name)", write="_constructor(?)")
for every column.
I've made types using the BLOB SqlTypeDescriptor
and a custom JavaTypeDescriptor
to do the conversion at the JDBC level, but how can I have my custom type wrap the column and parameters in the proper SQL functions? I'm not finding anything describing anything like this.
Edit:
To make this more concrete, this UDT (SDE ST_GEOMETRY
) must be build via database functions (ST_LineFromText
) or the defined UDT constructor (ST_LineString
). Likewise, to read them from the database, you have to "export" them into a certain format (ST_AsText
) for Java to read it. The regular approach of reading the fields of the type doesn't work in this case.
So:
create table geo_lines (
line SDE.ST_GEOMETRY
);
And:
@Entity
@Table(name="geo_lines")
public class GeoLine {
@Column(name="line")
@Type(type="org.example.MyStLineType")
// i'm wanting to be able to omit the following annotation
@ColumnTransformer(read="SDE.ST_AsText(line)",
write="SDE.ST_ST_LineFromText(?, 3857)")
private Polyline line;
}
So, all my type really needs from the user is the number (3857
in this case), which can be passed as a parameter, and everything else is standard boilerplate for any line. Repeat for the other types like points, polygons, etc.
wrap the column and parameters in the proper SQL functions
? – Samantha@org.hibernate.annotations.Type(type = "your.custom.DataType")
– Samantha3857
to be a parameter. The@ColumnTransformer(write)
must only have one question mark. It is checked by the regular expression inorg.hibernate.cfg.Ejb3Column#initMappingColumn
function. – Chide