When I create a custom hibernate Type, such as
public class CustomHibernateType extends AbstractSingleColumnStandardBasicType<Custom>
{
public CustomHibernateType()
{
// Notice the JsonBinarySqlTypeDescriptor class from @vladmihalcea's hibernate types library
super(JsonBinarySqlTypeDescriptor.INSTANCE, CustomHibernateTypeDescriptor.INSTANCE);
}
@Override
public String getName()
{
return "CustomHibernateType";
}
}
And create the Type Descriptor
// only constructor for brevity, can include more if needed
public CustomHibernateTypeDescriptor()
{
super(Custom.class, ImmutableMutabilityPlan.INSTANCE);
}
I find that when I am saving and retrieving data in my custom hibernate type descriptor, the class type used is different. It is saved as a jackson JsonNode
, which is expected as this is what is used in the JsonBinarySqlTypeDescriptor
class, however when it is retrieved it is retrieved in the unwrap method as a PGobject (which has a simple string value).
Should I be expecting this, or should I be expecting JsonNode in both directions? I have no problems processing the PGobject, it just wasn't expected so I'm wondering if there is some config missing somewhere.
The
wrap
method transforms the entity attribute type to the one that should be passed to the JDBCPreparedStatement
.The
unwrap
method transforms the object that was extracted from the JDBCResultSet
to the expected entity attribute type.