I’m developing a Java project with JPA / Hibernate and SQL Server DB.
I got an existent db where date fields are stored as int and datetime as float.
Does anyone know how can I implement a transparent conversion to a Calendar type in my domain class?
I must calculate the date in getter and setter or there’s a better way?
Thank you!
Marco
I would do it as follows:
UserTypeinterface.nullSafeGet()implementation, it will convert this string to a Joda DateTime orJava.util.Dateusing theSimpleDateFormatclass with format as “yyyyMMdd”.floatasString, assuming thefloatis of the format 20120828.190800. In thenullSafeGet()implementation, it too will convert this string to a Joda Datetime orjava.util.Dateusing theSimpleDateFormatclass with format as “yyyyMMdd.HHmmss”.nullSafeSet()will format back the data using the sameSimpleDateFormatin the respective classes.Hope this helps.