Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Class visibility between EARs and a Persistence Module

 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two EARs and a Persistence Module. What kind of archive (JAR or EAR etc.) shall I use for the Persistence Module so that an Entity in the Persistence Module is visible to both EARs?
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JBoss allow one to put the persistence module in a JAR file. That JAR then file must be deployed with the EARs. But what do the JavaEE specs say about it?
 
Maris Orbidans
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you will need to put JAR file in both EARs.
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maris Orbidans wrote:I think you will need to put JAR file in both EARs.


This would be an option but wouldn't that lead to an JNDI exception "JNDI name already exists" or the like?
 
Maris Orbidans
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darya Akbari wrote:
Maris Orbidans wrote:I think you will need to put JAR file in both EARs.


This would be an option but wouldn't that lead to an JNDI exception "JNDI name already exists" or the like?


AFAIK persistence module doesn't publish anything in JNDI.
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maris Orbidans wrote:AFAIK persistence module doesn't publish anything in JNDI.


That would be great, I will try it out with some application servers.

One last question concerning class visibility is, what will happen when one EAR method use another EAR's method both referencing the same entity? Wouldn't that lead to a class loader exception? How can one handle such requirements of reuse between EARs?
 
Maris Orbidans
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darya Akbari wrote:Wouldn't that lead to a class loader exception?


It depends whether your app server creates a classloader for each EAR. But if you have identical classes (with the same name) in both EARs then you shouldn't have any problems even if you got common classloader for all EARs.
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maris Orbidans wrote:It depends whether your app server creates a classloader for each EAR.


From the JavaEE spec view I think that this is how each app server should work.

Maris Orbidans wrote:But if you have identical classes (with the same name) in both EARs then you shouldn't have any problems even if you got common classloader for all EARs.


I think that should lead to a class loader exception, or what do you mean by common class loader?
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darya Akbari wrote:
One last question concerning class visibility is, what will happen when one EAR method use another EAR's method both referencing the same entity? Wouldn't that lead to a class loader exception? How can one handle such requirements of reuse between EARs?


I'm still looking for the right thing here
 
Maris Orbidans
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maris Orbidans wrote:
From the JavaEE spec view I think that this is how each app server should work.


It is not specified in J2EE. I am not sure about JEE.

Maris Orbidans wrote:But if you have identical classes (with the same name) in both EARs then you shouldn't have any problems even if you got common classloader for all EARs.

I think that should lead to a class loader exception, or what do you mean by common class loader?



If you have one classloader for all EAR files then you will get class version whichever happens to be first on classpath. If not it should not cause classloader exceptions either.
Why dont you try and tell us how it works.
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maris Orbidans wrote:Why dont you try and tell us how it works.


Before I try anything it must make sense. And so far I've not the feeling that we have anything really worth to try out. The solution must held for all application servers. Other than that would make portability nonsense.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic