Exactly, I have the same requirement. And I enabled it by registering a custom type for hibernation configuration.
For native queries, TypeDefs is not enough for hibernation to find a custom type. To determine the types of its types, type recognizers are needed.
@Query(value = "SELECT COUNT(*) FROM wsa_circuit_state_history ch WHERE ch.eff_dt between ?1 and ?2", nativeQuery = true) Integer countEffDateBetween(DateTime start, DateTime end);
In this case, hibernate tries to guess the type (org.joda.time.DateTime) from the converter types.
Type type = session.getFactory().getTypeResolver().heuristicType(typename);
Since there is no permission for DateTime.Then it gets the default type (serializable type). And the DateTime value is cast to its type, which is serialized and stored in the database, where it fails due to a large binary value.
To solve this problem, you need to register the DateTime type for the Hibernate configuration as
configuration.registerTypeOverride(new org.jadira.usertype.dateandtime.joda.PersistentDateTime(), new String[]{"org.joda.time.DateTime"});
source share