Search code examples
javajpaglassfishpersistenceclassloader

How to write a persistence provider for Glassfish


I have a special data storage (Empire RDF) I would like to use in my application with CMT enabled.

For that, I imagine I have to write a PersistenceProvider, that I will then declare in a persistence.xml, with a jta-datasource and associated connection properties.

As a consequence, I tried to, but I always face deployment issues related to PersistenceUnitLoader#loadPU (mainly the fact that it seems - to my ignorant eyes - that Glassfish confuses my PersistenceProvider with (Top/Eclipse)Link one).

So, what is the recommended way to create a PersistenceProvider for Glassfish for a non standard (read non related to a RDBMS) JPA implementation ?


Solution

  • Writing a PersistenceProvider is in fact a quite stepforward task.

    1. Create your persistence provider implementing the PersistenceProvider interface. In my case, it was a subclass of Empire JPAPersistenceProvider. Do not forget you can use properties read from persistence.xml using persistenceUnitInfos.getProperties(), but only in the PersistenceProvider#createContainerEntityManagerFactory method !
    2. In persistence.xml, write <provider>mycompany.MyProvider</provider>