I'm using EclipseLink in Glassfish with my JavaEE application and have some java.util.Locale-columns in my model classes which I would like to store as String-columns in my database tables.
I know Hibernate ships it's conversion annotations and I can build my own converter implementing org.eclipse.persistence.mappings.converters.Converter
. However, I have to depend on either of those libraries to use them.
Is there a way to get this functionality without directly depending on EclipseLink or Hibernate and staying with JPA spec?
JPA doesn't provide that feature :(... in fact, it's feature base is very, very basic. You can achieve the same by creating a virtual attribute, so you have a String field in your class, which is mapped, and then you create a virtual attribute with a setLocale(Locale) and Locale getLocale(), which transform the string into a Locale and return it or extract the string representation of the locale.
I know it's not WOW, but it's the only way to avoid using EclipseLink or Hibernate custom annotations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With