We are deploying multiple wars (no ear) into one jvm. Each war has its own web context and name. Each war's web-inf/lib has same persistence.jar.
In this jar, a persistence.xml is defined. In this persistence.xml, we define a jndi for EntityMangerFactory such as:
Since each war contains a jar which tries to register an emf with the same jndi name, deployments of every war fails with:
Caused by: org.jboss.msc.service.DuplicateServiceException: Service jboss.naming.context.java.jboss.EntityManagerFactories.myEMF is already registered.
Perviously we used jboss AS 6 and ear deployments with multiple ears and we did not have such problem.
In jboss 7, we decided to deploy war directly. But now we are stuck on this.
I'm not sure how that even worked in AS6. I would have expected a duplicate JNDI binding name problem. My guess is that the second war used to overwrite the first war's JNDI name, which in itself is a bug.
If we can parameterize the jndi name so that the parameter can be replaced at deployment time by war's deployment unit name, that would work too. But how to parameter the jndi name to incldue deployment unit name in it?
That is something that you could at build time. But then again, if the JNDI name is being referred in your code (I think it is), then that code needs to know of this dynamic JNDI name too. How do you make use of that JNDI name? If there are no references to that JNDI name in your code, then just not binding to the JNDI is an option.
Hi yangju, have you found the solution to this problem? I'm having the exact situation and still can't deploy wars...
Predrag hi and welcome to forums,
this is not a problem with AS7 but general problem in your application. JNDI is global and jndi name that you are using registers itself under global name that must be unique.
What you can do is bind the name to be application/war scoped so you can bind it under name(s):
/<your name> (not necessary to works)
or just <your name> for example EntityManagerFactories/myEMF
but as Jaikiran already said, the fact that this ever worked in AS6 was horrible bug.
On the other hand why do you even need this jndi bindig of EntityManagerFactory? are you accessing your EMF directly from JDNI even from outside of the application?
If not, you can just comment out this line of configuration and application will deploy without any problems.
Hi Tomaž and thanks!
Mine persistence.xml contained following line:
<property name="jboss.entity.manager.factory.jndi.name" value="java:/sleep-profiler-EntityManagerFactory"/>
which caused the problem when database module (compiled as JAR) was included in multiple wars.
I thought that this line was necessary for everything to work well. I was wrong
I removed this line from persistence.xml and now everything works just fine.
Thanks a lot!