Home » Category » Java Enterprise java bean & Java EE (EJB)

Java Enterprise java bean & Java EE (EJB): An MDB calling an Entity bean

302| Wed, 16 Jul 2008 22:14:00 GMT| mburke| Comments (5)
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() {
}
}

Keywords & Tags: mdb, calling, entity, bean, java, enterprise, ee, ejb

URL: http://java.itags.org/java-bean-j2ee/135949/
 
«« Prev - Next »» 5 helpful answers below.
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

damanjitkaur | Wed, 16 Jul 2008 22:15:00 GMT |

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

mburke | Wed, 16 Jul 2008 22:16:00 GMT |

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

damanjitkaur | Wed, 16 Jul 2008 22:17:00 GMT |

There doesn't seem to be a setting in Websphere to set the driver.

mburke | Wed, 16 Jul 2008 22:18:00 GMT |

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.)

jeanneboyarsky | Wed, 16 Jul 2008 22:19:00 GMT |

Java Enterprise java bean & Java EE (EJB) Hot Answers

Java Enterprise java bean & Java EE (EJB) New questions

Java Enterprise java bean & Java EE (EJB) Related Categories