TomEE and OpenEJB JPA deploy time enhancement

TomEE and OpenEJB got recently some deploy time enhancement features.

Deploy time enhancement : What is it?

Currently, it is available only for OpenJPA.

This feature is interesting. In fact, the best way to enhance entities with OpenJPA was to use the javaagent (activated by default in openejb). But this solution is not all clean. Without enhancing your entities, you (generally) have bad performances and some features are missing (even with others providers…yes, even hibernate!). Thus, you had to enhance your entities at build time…so your byte code was modified 😦 (but very often, in real life, that’s not an issue).

The advantage to deploy time enhancement is that byte code is modified but only in the deployment binaries.

How to activate it?

First, ask for deploying time enhancement, as usually done with OpenEJB/TomEE, add a system property: openejb.jpa.deploy-time-enhancement=true

Then this feature has some more configuration (properties too):

  • openejb.jar.enhancement.include
  • openejb.jar.enhancement.exclude

It simply defines which files should be included/excluded. The format is java regex one and is applied on file paths.

What does it do?

It will enhance selected jars (or all if no include/exclude is configured) with OpenJPA PCEnhancer (used by openjpa maven plugin). To enhance them, it will explode them, then repackage them. The original jars will be deleted and a new one will be created with the suffix -enhanced.

Final note

If you have any need concerning this feature or any issue, feel free to post a mail to, we’ll try our best to make this feature better ;).

12 thoughts on “TomEE and OpenEJB JPA deploy time enhancement

  1. V. Jenks

    This is very vague. Where do I add these properties? Pretend I’m a beginner to this, please. I’ve been struggling with this issue for days and I’m starting to think it’s hopeless. TomEE seemed like a great, “simple” alternative to a full on app server but this has been a huge roadblock to getting even a simple example to run successfully.

  2. V. Jenks

    I added “openejb.jpa.deploy-time-enhancement=true” to and I still get this error – the root of all evil:

    “org.apache.openjpa.persistence.ArgumentException: This configuration disallows runtime optimization, but the following listed types were not enhanced at build time or at class load time with a javaagent:”

    It didn’t change anything for me.

    Any ideas? Using TomEE

    1. rmannibucau Post author


      it should be in conf/ or as JVM

      That said deploy time enhancement matches some particular usage. Default uses javaagent (in place by default) and deploy time enhancement is useless in this case.

      1. V. Jenks

        Thank you VERY much! This worked and the error is gone. I’m fairly new to this, so I don’t really understand the rest (java agent, deploy-time enhancement, etc.) I just need to be able to develop a simple app and deploy it to TomEE on my VPS. I’d be thrilled to get that far.

        The enhancement problem seems to be solved, but I’m getting a new, stubborn error that I can’t seem to get around now. Any chance you’ve seen this? I’m also unable to Google up an answer for this. When I deploy, there are no exceptions now…but when running a simple select query from a single table, I get this one:

        “Apr 23, 2014 9:59:34 AM org.apache.openejb.core.stateless.StatelessInstanceManager createInstance
        SEVERE: The bean instance PlayerBean threw a system exception:javax.persistence.PersistenceException: Explicit persistence provider error(s) occurred for “TomEETestPU” after trying the following discovered implementations: org.apache.openjpa.persistence.PersistenceProviderImpl from provider: org.apache.openjpa.persistence.PersistenceProviderImpl
        javax.persistence.PersistenceException: Explicit persistence provider error(s) occurred for “TomEETestPU” after trying the following discovered implementations: org.apache.openjpa.persistence.PersistenceProviderImpl from provider: org.apache.openjpa.persistence.PersistenceProviderImpl
        at javax.persistence.Persistence.createPersistenceException(
        at javax.persistence.Persistence.createEntityManagerFactory(
        at javax.persistence.Persistence.createEntityManagerFactory(
        at tomeetest.model.service.PlayerBean.(
        Caused by: org.apache.openjpa.util.GeneralException: org.xml.sax.SAXException: file:/C:/TomEETest/build/web/WEB-INF/classes/META-INF/persistence.xml [Location: Line: 8, C: 15]: org.xml.sax.SAXParseException; systemId: file:/C:/TomEETest/build/web/WEB-INF/classes/META-INF/persistence.xml; lineNumber: 8; columnNumber: 15; cvc-complex-type.2.4.a: Invalid content was found starting with element ‘provider’. One of ‘{“”:non-jta-data-source, “”:mapping-file, “”:jar-file, “”:class, “”:exclude-unlisted-classes, “”:shared-cache-mode, “”:validation-mode, “”:properties}’ is expected.
        at org.apache.openjpa.lib.meta.XMLMetaDataParser.parseNewResource(
        at org.apache.openjpa.lib.meta.XMLMetaDataParser.parse(
        at org.apache.openjpa.lib.meta.XMLMetaDataParser.parse(
        at org.apache.openjpa.lib.meta.XMLMetaDataParser.parse(

        … 40 more”

        My classes, entities, beans are in /src/java My persistence.xml is in /src/conf and looks like this (generated by Netbeans 8.0):



        …regardless of whether I use version=2.0 or 2.1, the error is the same.

        When this is all done and I’ve *finally* successfully deployed a small, simple working application to TomEE using OpenJPA, I will write up an extensive tutorial/how-to and will be sure to credit you for the help you’ve given me. There just isn’t enough information out there on how to get started with this. It can be very frustrating.

        I appreciate it, thanks again!

  3. rmannibucau Post author

    Hmm, you mix things in your persistence.xml, JTA and config inline in properties (should be for resource local etc)

    PS: maybe open a thread on tomee list, would be more efficient than comments on a blog

    1. V. Jenks

      OK, I’ll do that, thanks. RESOURCE_LOCAL doesn’t change anything – should have mentioned that. I’d be stoked if it was a simple formatting problem.

    1. V. Jenks

      Ha! That worked! I’m embarrassed that I missed something so simple. Thanks, yet again.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s