Skip to Content

JPA/EJB3: DC reuse

Hi developers,

In my project, I am using an ejb dc with JPA facet enabled.

It now contains both EJBs and entities.

The project has grown big, so I would like to create new EJBs in new DCs.

How can I use in DC 1 the entities/persistence context defined in DC 2?

Thanks, regards


Add comment
10|10000 characters needed characters exceeded

1 Answer

  • Posted on May 21, 2010 at 11:05 PM

    Hi Vincenco,

    I strongly recommend you stay with one DC and a clean package structure. In JPA-theory, you can reference a jar file (e.g. content of DC 1) in persistence xml of DC 2 where the persistence context is defined. But if you want to use JPA Facet and JPA Validator on both DCs, you will get into trouble with the tools - you probably cannot activate JPA Facet in DC 1 without an - unwanted - persistence.xml in it.

    Another example: With JPA Facet and SAP JPA as persistence provider, you cannot have a mapped superclass in DC 2 and its extending class in DC 1. DC 1 will not build because the JPA Validator does not find the mapped superclass in DC 2 and you cannot deactivate the validator. Furthermore, the dictionary-tables of DC 1 will not be built at all or not correct.

    There are more traps like this. The SAP tooling supports an EJB DC with JPA facet that contains ALL Entities for this persistence context, but no DC-splitting. I also recommend to put all services that work on attached entities (that is with EntityManager) in this DC.



    BTW Take a look at the excellent answers from Adrian Goerler in this forum about details and limitations of SAP JPA (e.g. about lazy load, orphan removal).

    Add comment
    10|10000 characters needed characters exceeded