Hibernate currently provides a way to define custom types. Either internal or user types.
In some situations, this custom type may have to access the entity identifier.
Concrete use case: compute a custom value using the entity identifier (may be null depending on the id strategy which is used).
This is currently possible from the nullSafeGet method through the owner but this is not possible to access that identifier from the nullSafeSet Method.
So, the proposal would be to review the Hibernate internals to allow exposing this identifier as follow on the UserType interface and call this new method instead of the current one
{code:java}public interface UserType {
// hibernate would call this method internally // id parameter is the owner/entity identifier default void nullSafeSet(PreparedStatement st, Serializable id, Object value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException { nullSafeSet(st, value, index, session); }
void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException; }{code}
The Type interface would also need to be updated the same way to allow transmitting the id from the caller stack. See CustomType.
Proposed change is retro-compatible. |
|