Originally posted by Khaled Mahmoud: I am new to EJB and preparing for the Sun Certified Business Component Developer. I am now reading the book EJB 3.0 for Oreilly.
How many persistence.xml and application can have?
In the chapter about EntityManger section 5.3 the book says one of the places that a persistence.xml file located is at :
A plain JAR file within the classpath of a regular Java SE program
Does this mean that I can deploy many persistence units in java application each with its own persistence.xml file in a seperete jar file.
Yes, of course it works. I've just tried it. I've created an entity bean and packed it into a JAR file with a persistence.xml (with <persistence-unit name="domain2"> ) and i've deployed it into my EJB 3.0 container (JBoss).
Then, i've created an other JAR with an other persistence.xml(with <persistence-unit name="domain1"> ) and i've put an other entity bean with a stateless session bean into it. The stateless bean had some methods to persist and read out my entity beans from "both of the JARs" (corretly said: persistence units).
Of course, i've injected (dependency injection) TWO EntityManager references (respectively for both persistence units) into the stateless session bean like this: