I recently ran into a post where someone said they were dropping TopLikn Essentials in favor of OpenJPA. At the time I was searching for some assistance in fixing some rather impossible to diagnose (mostly due to toplink’s incomprehensible stack traces) ClassNotFoundException. I eventually figured out that toplink’s class loader was broken in some way which I couldn’t fix, and that meant I couldn’t have my entity classes subclass something from some other jar. Or whatever, I haven’t fully diagnosed the problem, and instead decided to spend my time on getting OpenJPA installed.
This turned out to be quite easy – I just downloaded the openjpa binaries and copy the openjpa jar and lib/*.jar from that disitribution into glassfish/domains/domain1/lib, then changed my persistence.xml to specify OpenJPA as the persistence provider:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
Even though OpenJPA is more strict about not using field accesses when using property-mode fields (even inside the same class, you can’t use this.x) I’m so happy that it told me this with wonderfully clear error messages, it seems worth the effort to fix my code (by right-clicking a lot and picking Refactor > Encapsulate Field).
Thanks go to Sahoo for showing me how to do this: