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  users@openejb.apache.org, we’ll try our best to make this feature better ;).

Advertisements

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.

    Reply
  2. V. Jenks

    I added “openejb.jpa.deploy-time-enhancement=true” to catalina.properties 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.6.0.1

    Reply
    1. rmannibucau Post author

      Hi

      it should be in conf/system.properties or as JVM system.properties.

      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.

      Reply
      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(Persistence.java:244)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:186)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:72)
        at tomeetest.model.service.PlayerBean.(PlayerBean.java:28)
        …etc…
        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 ‘{“http://java.sun.com/xml/ns/persistence”:non-jta-data-source, “http://java.sun.com/xml/ns/persistence”:mapping-file, “http://java.sun.com/xml/ns/persistence”:jar-file, “http://java.sun.com/xml/ns/persistence”:class, “http://java.sun.com/xml/ns/persistence”:exclude-unlisted-classes, “http://java.sun.com/xml/ns/persistence”:shared-cache-mode, “http://java.sun.com/xml/ns/persistence”:validation-mode, “http://java.sun.com/xml/ns/persistence”:properties}’ is expected.
        at org.apache.openjpa.lib.meta.XMLMetaDataParser.parseNewResource(XMLMetaDataParser.java:427)
        at org.apache.openjpa.lib.meta.XMLMetaDataParser.parse(XMLMetaDataParser.java:347)
        at org.apache.openjpa.lib.meta.XMLMetaDataParser.parse(XMLMetaDataParser.java:324)
        at org.apache.openjpa.lib.meta.XMLMetaDataParser.parse(XMLMetaDataParser.java:297)

        … 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):

        <!—->

        TomEETestDS
        org.apache.openjpa.persistence.PersistenceProviderImpl
        tomeetest.model.Transaction
        tomeetest.model.Player
        tomeetest.model.Transactionreason
        false

        …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

    Reply
    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.

      Reply
    1. V. Jenks

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

      Reply

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s