1

Is there any javax persistance annotations just like hibernate @Type

@LastModifiedDate
@Column(name = "LAST_MODIFIED_DATE")
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
private DateTime lastModifiedDate = DateTime.now();

or is there some other way to get free from hibernate @Type annotations. just removing it throws binary too long exception from database.

Vlad Mihalcea
  • 142,745
  • 71
  • 566
  • 911
Saurabh Kumar
  • 16,353
  • 49
  • 133
  • 212
  • You can never get totally free from Hibernate specific since JodaTime is not in the JPA spec ... yes you can specify persistence properties BUT they are Hibernate persistence properties so will not work with other providers – Neil Stockton Aug 22 '15 at 13:37
  • It is possible with JPA 2 (Java EE 7) using custom converters. This seems to be a duplicate of http://stackoverflow.com/questions/9783577/how-to-use-joda-time-with-jpa-eclipselink – OndroMih Aug 22 '15 at 17:24
  • errm, JPA 2.1 actually, AttributeConverter – Neil Stockton Aug 22 '15 at 18:48

2 Answers2

1

Yes you can. Just set the following JPA property in persistence.xml:

<property name="jadira.usertype.autoRegisterUserTypes" value="true"/>
Vlad Mihalcea
  • 142,745
  • 71
  • 566
  • 911
  • Good answer,but mind that this is not a standard JPA property and is probably supported only by hibernate – OndroMih Aug 22 '15 at 18:16
0

In JPA 2, the solution is to use a custom JPA converter, which converts a jodatime value to a Java.sql.Date value. Here is a gret blog post on mapping new Java 8 date time types, which are basically jodatime types standardized in Java 8 library: https://weblogs.java.net/blog/montanajava/archive/2014/06/17/using-java-8-datetime-classes-jpa

With JPA 1, no converters are supported out of the box, and you may either use a converter specific to your JPA implementation (e.g. hibernate) or resort to making the jodatime field transient and encode/decode it to another Date field using PostLoad and Preupdate listeners

OndroMih
  • 7,280
  • 1
  • 26
  • 44