开发者

JPA persistence.xml share same jar file

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 fil开发者_高级运维e.

What do yo think?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜