This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes EJB3 2 client apps and 2 different databases Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB3 2 client apps and 2 different databases" Watch "EJB3 2 client apps and 2 different databases" New topic
Author

EJB3 2 client apps and 2 different databases

eve agostini
Ranch Hand

Joined: Nov 01, 2005
Posts: 43
Hi
is it possible to invoke the same EJB3 Session Bean from two different client applications (web application) but in such a way that each different app persists on a different database?
Thanks!

Eve
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30136
    
150

Eve,
You would have to deploy the EJB twice to make that happen. Each app could call a different ear that points to the two databases.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
eve agostini
Ranch Hand

Joined: Nov 01, 2005
Posts: 43
Thanks for your answer

I think I'm putting the persistence.xml file in the wrong place.

I've read I can:
define the unit by placing a JAR file in the lib directory of the EAR, the persistence unit will automatically be visible to all modules in the EAR


So, that's what I tried to do.

Here is the structure of my appplication:


and this is the structure of the DB2 jar file:



I get this exception:
java.lang.IllegalStateException: Unable to retrieve EntityManagerFactory for unitName provaPU


I also tried to put the persistence.xml file directly in the archive (without the META-INF directory) but in this case the application won't event start and I'm getting this exception:
Caused by: java.lang.RuntimeException: Could not resolve a persistence unit corresponding to the persistence-context-ref-name [prova.NewSessionBean/entityManager] in the scope of the module called [EnterpriseApplication3#EJBModule1.jar]. Please verify your application.

Here is also the persistence.xml file itself:


Thanks for your help

Eve
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: EJB3 2 client apps and 2 different databases
 
Similar Threads
JBoss 5 and EJB 3 Webservices
EJB3: Build, Packaging and Deploying: Industry Standards
How to invoke an EJB3 from a simple client
differnce between EJB 3 and hibernate
JDO and the new persistence api