I'm researching how to handle time zones with JPA backed by Hibernate. Unfortunately our schema does not dictate that all date/time values are stored in UTC, so on the back-end alone (disregarding display), we need to be able to pass the TimeZone down dynamically based on the current back-end being written to. I won't enumerate all of the details here, but bottom line, we need to be able to pass the TimeZone down on every query if needed.
I found
http://www.hibernate.org/100.html , which is a good start, but all of the code snippets there and the general solution entail statically determining a TimeZone.
Using ParameterizedType with a time zone parameter is still static as I have to define the TimeZone in the declaration of entities.
From what I can tell, my best bet is to have a component that dynamically determines the active back-end, and its TimeZone at runtime to pass into getTimestamp(String, Calendar) and setTimestamp(int,Timestamp,Calendar). I could either access this component directly from the UserType code, or I could hide it behind an interface and pass a provider class-name in with a ParameterizedType.
What would be ideal, is if I could *explicitly* pass in the time-zone when I am creating, parameterizing, and executing a Query. For example, perhaps there is a way to access query hints in a UserType and I could define my own Query hint? It could be called something like "mycompany.timezone" and be ignored by hibernate.
Any thoughts or ideas? Thanks ahead of time for any help.
Updated: Removed rogue comma from link.