aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Persistence.xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Persistence.xml" Watch "Persistence.xml" New topic
Author

Persistence.xml

Khaled Mahmoud
Ranch Hand

Joined: Jul 15, 2006
Posts: 361
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.


SCJP, SCJD,SCWCD,SCDJWS,SCEA 5 MCP-C#, MCP-ASP.NET - http://www.khaledinho.com/
Life is the biggest school
Andor Nemeth
Greenhorn

Joined: Jul 06, 2007
Posts: 16
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:

@PersistenceContext (unitName="domain1")
private EntityManager em1;

@PersistenceContext (unitName="domain2")
private EntityManager em2;

persist() and find() have worked for both of the persistence units.

I hope I've helped you.
[ July 12, 2007: Message edited by: Andor Nemeth ]

SCJP 5<br />SCBCD 5 (next target)
Satya Maheshwari
Ranch Hand

Joined: Jan 01, 2007
Posts: 368
You can also have more than 1 persistence unit defined in a single persistence.xml.


Thanks and Regards
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Persistence.xml