Win a copy of Head First Android this week in the Android 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Persistence.xml

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

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 ]
 
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can also have more than 1 persistence unit defined in a single persistence.xml.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic