File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes Multiple database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Multiple database" Watch "Multiple database" New topic

Multiple database

Tmmet Johnson
Ranch Hand

Joined: Nov 03, 2004
Posts: 56
I have a question.
In my StatelessSessionBean.,I have a bean method set to transaction attribute ,Required.
Another method set to transaction attribute,RequiredNew as below.
I am not using XA datasource .And, I don�t need a two phase commit.
I get the error message at runtime in methodB-
�An illegal attempt to use multiple resources that have only one-phase capability has occurred within a global transaction�.
Can anyone let me know why I get this error?

MethodA (int i) //method A set to Required
//Makes call to Data Access Object to perform update in Oracle database
//Calls method B


methodB( int i) // methodB is set to RequiresNew

if(i == 100){
//makes call to Data Access Object to perform insert in Oracle database
//makes call to Data Access Object to perform update in DB2 database

Babji Reddy
Ranch Hand

Joined: Jan 24, 2006
Posts: 106
Looks like you have setup Datasources for Oracle and DB2 in your AppServer and using the datasource to obtain a connetion. you will get this exception when you use two different resources (Database, JMS source etc) in a single EJB Transaction.

One way of getting around is use fixed connection instead of pooled connection, for one of the DBs. And commit/rollback the fixed connection accordingly.

Try making the second method with 'Not supports' transaction attributes, this way the second method will not run in a transaction, but you cannot do commit/rollback on the connection that you use in second method.
(If the exception still occurs, (not likely) make a separate EJB that runs in 'Not supports' transaction mode and call it from method1.
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
I believe the problem is caused by accessing multiple resources (databases) within a single transaction. There are two solutions.

1. Switch to XA drivers and XA-capable data sources.

2. Declare separate methods for separate DBs (best).

SCJP 1.4, SCWCD 1.3, SCBCD 1.3
I agree. Here's the link:
subject: Multiple database
It's not a secret anymore!