Mixing JPA with JAXB/JAXWS
With JavaEE 6, you can publish an SOAP WebService as easy as 1-2-3. It mixes well with JPA, but I give you a small advice: if you need bidirectional ORM mappings, one of them MUST be @XmlTransient. Otherwise, you will receive a com.sun.xml.ws.streaming.XMLStreamReaderException ("unexpected XML tag. expected: {yourns}yourtag but found: {http://schemas.xmlsoap.org/soap/envelope/}Envelope").
Booleans in JPA (the portable way)
If you want to map a boolean value in JPA, you will have a headache if your RDBMS is Oracle. Since it does not support a boolean data type, you usually create a CHAR(1) 'Y'/'N' field and use a lot of bad words to describe the feeling you have when you find out that JPA does not support boolean-to-char convertion.
A nice and portable workaround is described here. The trick is to remember why getter/setter encapsulation is a good pratice - you can do a lot more than just plain old get/set:
private char enabled; public boolean isEnabled() { return enabled == 'Y'; } public void setEnabled(Boolean enabled) { this.enabled = (enabled ? 'Y' : 'N'); }
Hibernate JPA and Enums
Assume you have a simple enum:
public enum Status { ACCEPTED, REJECTED, NOTREADDEN }
And your legacy database stores it as ordinal values (ACCEPTED = 0, REJECTED = 1, NOTREADDEN = 2). For reasons lost in time, DBA created the column as "varchar". If you want to use JPA, you will have a bad time using Hibernate:
java.lang.IllegalArgumentException: No enum const class mypkg.Status.1 java.lang.Enum.valueOf(Enum.java:196) org.hibernate.type.EnumType.nullSafeGet(EnumType.java:110)
After digging into EnumType.java, I noticed it is hardcoded "if-varchar-then-name-else-ordinal". I assume they never dealed with ancient, legacy databases.
If I switch to TopLink, it works as expected... One thumb down to Hibernate...