Win a copy of High Performance Python for Data Analytics this week in the Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Persistence Unit Scoping

 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Assume you have an EAR structure like this:
lib/actionBazaar-common.jar
actionBazaar-ejb.jar
actionBazaar-web.jar

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.
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Prasad

From the ejb-3.0-specification, point 6.2.2

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
 
joke time: What is brown and sticky? ... ... ... A stick! Use it to beat this tiny ad!
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic