Assume you have an EAR structure like this:
A persistence unit 'actionBazaar' is defined in both the actionBazaar-common.jar and actionBazaar-ejb.jar
If we try to use the 'actionBazaar' unit in the EJB module, the local persistence unit will be accessed. - I understand this.
However, if we try to use the the 'actionBazaar' unit in the Web module, which of the two persistence units will be used ?
My point here is, the web module has access to both these units, because the EAR class loader will load the actionBazaar-common.jar persistence unit and EJB class loader will load the actionBazaar-ejb.jar persistence unit.
Since, WAR Class loader, is the child of EJB class loader and EJB class loader is a child of EAR class loader, WAR module can access both the persistence units.
Hence which one will be invoked ?
Please correct me if I am making any mistake in understanding the scoping.
A persistence unit that is defined at the level of an EJB-JAR,WAR,
or application client jar is scoped to that EJB-JAR, WAR, or application jar respectively and is visible to
the components defined in that jar or war. A persistence unit that is defined at the level of the EAR is
generally visible to all components in the application.
If you try to use a persistence unit from actionBazaar-web.jar, you are getting the persistence unit from lib/actionBazaar-common.jar, because in war file you have not a persistence unit. The web module only has access to ear level persistence unit.
You must follow this rule and forget the class loader in persistence unit scopes. I hope it has helped you