permaculture playing cards*
The moose likes EJB and other Java EE Technologies and the fly likes An  MDB calling an Entity bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "An  MDB calling an Entity bean" Watch "An  MDB calling an Entity bean" New topic
Author

An MDB calling an Entity bean

M Burke
Ranch Hand

Joined: Jun 25, 2004
Posts: 388
I am getting an error when the process leaves the onMessage() of the MDB. It is related to the entity bean that is trying to add a row to a cloudscape database.

"An illegal attempt to commit a one phase capable resource with existing two phase capable resources has occurred."

Phase? What are they refering to? I am using IBM MQ as my JMS service.

MDB code...

package mdbBeans;

import javax.ejb.CreateException;
import javax.jms.TextMessage;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
* Bean implementation class for Enterprise Bean: TaxMDB
*/
public class TaxMDBBean
implements javax.ejb.MessageDrivenBean, javax.jms.MessageListener {
private javax.ejb.MessageDrivenContext fMessageDrivenCtx;
/**
* getMessageDrivenContext
*/
public javax.ejb.MessageDrivenContext getMessageDrivenContext() {
return fMessageDrivenCtx;
}
/**
* setMessageDrivenContext
*/
public void setMessageDrivenContext(javax.ejb.MessageDrivenContext ctx) {
fMessageDrivenCtx = ctx;
}
/**
* ejbCreate
*/
public void ejbCreate() {
}
/**
* onMessage
*/
public void onMessage(javax.jms.Message msg) {
TextMessage tm = (TextMessage) msg;
String lmsg = tm.toString();

int len = lmsg.lastIndexOf("\n");
lmsg = lmsg.substring(len + 1);


System.out.println("Message received: " + lmsg);

int key;
key = Integer.parseInt(lmsg);
try {
InitialContext initialContext = new InitialContext();

TaxEjbEntityLocalHome TaxH = (TaxEjbEntityLocalHome)initialContext.lookup("java:comp/env/ejb/TaxEjbEntity");
TaxEjbEntityLocal tl = TaxH.create(key);
tl.setTaxName(("***" + key + "local" + "***"));
} catch (NamingException e) {

e.printStackTrace();
} catch (CreateException e) {

e.printStackTrace();
}

}
/**
* ejbRemove
*/
public void ejbRemove() {
}
}
Damanjit Kaur
Ranch Hand

Joined: Oct 18, 2004
Posts: 346
Hi,

Here is a link that explains two phase commit.

http://www.jguru.com/faq/view.jsp?EID=20929

Regarding your problem-

If cloudscape jdbc provider that you are using supports two phase commit transaction.

I don't know much about cloudscape database but I found something about two phase and one phase commit which relates with the cloudscape jdbc provider that you might be using. Chances are that you might be using the one which supports one phase commit.
Here is the link from where I got this information:
http://publib.boulder.ibm.com/infocenter/wasinfo/index.jsp?topic=/com.ibm.websphere.nd.doc/info/ae/ae/rdat_minreq.html
M Burke
Ranch Hand

Joined: Jun 25, 2004
Posts: 388
Thanks for the info. I do notice there are two drivers, on for one-phase and another for two-phase. The two-phase driver is called Cloudscape JDBC Provider (XA) com.ibm.db2j.jdbc.DB2jXADataSource. But I am not sure how to go about telling the system to use it in WAS
Damanjit Kaur
Ranch Hand

Joined: Oct 18, 2004
Posts: 346
Hi,

I suppose you are using Weblogic Application Server (WAS). I found on following link some info about "When to Use a Tx Data Source" which is your case.
http://e-docs.bea.com/wls/docs70/adminguide/jdbc.html#jdbc002

and the second link specifies about configuring datasource.

http://e-docs.bea.com/wls/docs70/jdbc/programming.html#programming030
M Burke
Ranch Hand

Joined: Jun 25, 2004
Posts: 388
There doesn't seem to be a setting in Websphere to set the driver.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30361
    
150

The entity bean is associated with a datasource. (It must be or nothing would work.)

I didn't catch if you are using WAS or WSAD. In WAS, you can set the datasource by drilling down to it under the resources link. In WSAD, you can set the datasource by clicking on the datasource tab of the server (in the servers perspective.)


[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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: An MDB calling an Entity bean