Creation timestamp and last update timestamp with Hibernate and MySQL

For a certain Hibernate entity we have a requirement to store its creation time and the last time it was updated. How would you design this?

  • What data types would you use in the database (assuming MySQL, possibly in a different timezone that the JVM)? Will the data types be timezone-aware?

  • What data types would you use in Java (Date, Calendar, long, …)?

  • Whom would you make responsible for setting the timestamps—the database, the ORM framework (Hibernate), or the application programmer?

  • What annotations would you use for the mapping (e.g. @Temporal)?

I’m not only looking for a working solution, but for a safe and well-designed solution.

18 Answers
18

Leave a Comment