简体   繁体   中英

persistence.xml in EAR and JAR file. Which to use

I have an application that is packed in a JAR file (my EJB files). This is then packed in an EAR file.

Both of these packages have their own persistence.xml file. Which one does glassfish (or any server for that matter) use? Does it look at both files? Or only one of them?

Which one does glassfish (or any server for that matter) use?

According to JPA specification :

8.2 Persistence Unit Packaging

Within Java EE environments, an EJB-JAR, WAR, EAR, or application client JAR can define a persis- tence unit. Any number of persistence units may be defined within these scopes. A persistence unit may be packaged within one or more jar files contained within a WAR or EAR, as a set of classes within an EJB-JAR file or in the WAR classes directory, or as a combination of these as defined below...

Edit:

If I have a persistence unit defined in both XML files with the same name, which one will it use?

By default the one defined in your .jar.

8.2.2 Persistence Unit Scope

A persistence unit that is defined at the level of the EAR is generally visible to all components in the application. However, if a persistence unit of the same name is defined by an EJB-JAR, WAR, or application jar file within the EAR, the persistence unit of that name defined at EAR level will not be visible to the components defined by that EJB-JAR, WAR, or application jar file unless the persistence unit reference uses the persistence unit name # syntax to specify a path name to disambiguate the reference...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM