CompositeUserType hashCode/equals

I have a complex CompositeUserType that takes a given Java object and persists it into a “standard” column db type, but also optionally stores a couple of transformations of the value into different columns.

For example a string might be persisted into 1-3 different columns:

  1. Column for original varchar value
  2. Column for a hash/checksum of the value
  3. Column for another optional transformation

In this situation, what is the expected contract of hashCode/equals for my UserType?

Should I only do hashCode/equals on the original string? Or should I include the optional transformations in the hashCode/equals calculation as well, even though they are all derived from the original string value?

What’s the point of including stuff in equals/hashCode if it is fully derived from some other state? I’d say it depends if this derived state in your Java model is mutable. If it’s immutable, you don’t even have to keep it as “state” i.e. you could just always compute it on demand.