title: How to call a Java method on any read/write access of a database column through Hibernate
body: <p>I have a two-column database table that contains a mapping of usernames to payload values.</p>
  
  <pre><code>+ -------- | ------- +
  | username | payload |
  + ---------| --------+
  | foobar   | 123.abc |
  + ---------| --------+
  </code></pre>
  
  <p>For various (admittedly stupid, but unavoidable) reasons, the payload (a String) needs to be stored in a weird <em>pseudo-reverse</em> order (basically a reversible hash - 'abc.123' is stored as '123.abc').</p>
  
  <p>I've written a method to do the reversal of the value which works fine:
  <code>public String reversePayload(validPayload) {...}</code></p>
  
  <p>Is there a way that I can configure Hibernate to call that function whenever it reads or writes from/to the <code>payload</code> column, so that I can have the code that actually uses that payload value deal with it in "standard" form? </p>
  
  <p>(I've already tried modifying the DAO to do it - which I think will work - but our DAO isn't really abstracted very nicely, and I ended up having to add 10 different calls to <code>reversePayload</code>, one for every method that calls <code>currentSession().saveOrUpdate(user)</code> or <code>currentSession().get('&lt;username&gt;')</code>)</p>