132 words

Finding out the JPA provider

2011-08-30 12:02

Do you have any preferred way of finding out whether ObjectDb is my EntityManager's JPA Provider?

I know there are problems with using getDelegate ( http://weblogs.java.net/blog/ss141213/archive/2009/05/be_careful_whil.html ) but on the other hand unwrap is not very portable ( https://forums.oracle.com/forums/thread.jspa?threadID=2149162 ). It would be nice if the <provider> element of the PeristenceUnit were visible in one of the Properties sets returned by the EntityManager and EntityManagerFactory, but its not.

So I am left with

    EntityManager.getDelegate() instanceof com.objectdb.jdo.PMImpl


    EntityManagerFactory instanceof com.objectdb.jpa.EMF.

Or putting something in my properties for this sole purpose...

    <property name="uk.co.his.jpa.provider" value="ObjectDb" />

At the momment I'll stick with the latter...

JFK's picture
Joined on 2011-08-24
User Post #12
2011-08-31 16:24

Your solution is fine, but you may also simply check for the "objectdb.home" property.

In the EntityManagerFactory:

    boolean isObjectDB = emf.getProperties().get("objectdb.home") != null;

Or in the EntityManager:

    boolean isObjectDB = em.getProperties().get("objectdb.home") != null;
ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
support's picture
Joined on 2010-05-03
User Post #582

Post Reply

Please read carefully the posting instructions - before posting to the ObjectDB website.

  • You may have to disable pop up blocking in order to use the toolbar (e.g. in Chrome).
  • Use ctrl + right click to open the browser context menu in the editing area (e.g. for using a browser spell checker).
  • To insert formatted lines (e.g. Java code, stack trace) - select a style in the toolbar and then insert the text in the new created block.
  • Avoid overflow of published source code examples by breaking long lines.
  • You may mark in paragraph code words (e.g. class names) with the code style (can be applied by ctrl + D).
  • Long stack traces (> 50 lines) and complex source examples (> 100 lines) should be posted as attachments.
Maximum file size: 32 MB