views:

31

answers:

1

Hi! I'm wondering if I can share the same jar file for several persistence units.. I mean: I have two persistence units described in my persistence.xml file and the entities are not in the same JAR. Entities are in a separated JAR file but, in that one, there are entites for both persistence units. I think I red somewhere that I coould use tag something like this: externalEntities.jar#com.mycompany.EntityA so I could separate them. I tried this solution and it doesn't work. Now I guess that it couldn't be done to package all entities (for two different persistence units) in the same JAR file.

What do yo think?

A: 

I'm not sure I understood the question but did you try to declare your jar with the jar-file element. From the spec (section 6.2.1.6):

One or more JAR files may be specified using the jar-file elements instead of, or in addition to the mapping files specified in the mapping-file elements. If specified, these JAR files will be searched for managed persistence classes, and any mapping metadata annotations found on them will be processed, or they will be mapped using the mapping annotation defaults defined by this specification. Such JAR files are specified relative to the root of the persistence unit (e.g., utils/myUtils.jar).

...

Example 3:

<persistence-unit name="OrderManagement3">
  <jar-file>order.jar</jar-file>
  <jar-file>order-supplemental.jar</jar-file>
</persistence-unit>

A persistence unit named OrderManagement3 is created. Any annotated managed persistence classes found in the root of the persistence unit are added to the list of managed persistence classes. If a META-INF/orm.xml file exists, any classes and mapping information contained in it are used as specified above. The order.jar and order-supplemental.jar files are searched for managed persistence classes and any annotated managed persistence classes found in them and/or any classes specified in the orm.xml files of these jar files are added. The transaction-type, data source and provider are as described above.

Pascal Thivent