Using custom data type in Hibernate

Why need custom data type?

I have a java.util.Calendar object which I want to persist in the db, along with the TimeZone. Suppose I am working with a db which does not have support for storing TimeZone. How do I proceed? One of the easiest solutions would be to store the entire timestamp as a VARCHAR. Granted, but how do I instruct Hibernate to use a java.util.Calendar object instead of a String? Its done by annotating with @Type(type=””), where type should be the fully qualified name of a class implementing the org.hibernate.usertype.UserType interface.

Custom UserType

Hibenate Entity


The sources can be found

Leave a Reply

Your email address will not be published. Required fields are marked *