I have built a session bean which will access CMP entity bean to create the record. However, I need to have an unique primary key before create the record. So I call a stateless session bean to retreive next sequence number from oracle DB, and then create the entity with the new PK. CounterLocal counter = counterHome.create() ; user = userHome.create(counter.getNextVal, name, post, tel) ; When I run in WebSphere UTest Client, it throw the following exception : TransactionIm E WTRN0062E: An illegal attempt to use multiple resources that have only one-phase capability has occurred within a global transaction. LocalTransact E J2CA0030E: Method enlist caught java.lang.IllegalStateException
You're triggering a commit between what WebSphere interprets as two separate databases, via it seeing two separate connections. The first call to look up the record is the first database and the second call on the CMP bean is the second database. WebSphere does not understand that these are the same database, although by using resource references it can optimize away the 2PC, but thats not guarenteed.
In this case two indepedent database calls isn't neccessary so I'd suggest resolving this in one of three ways...
Create a finder method on the CMP that searches for max record. This way all database calls are controlled by the CMP and WebSphere won't think your making two separate connections.
Add the logic to retrieve the key inside the CMP itself.
Add the logic to create the primary key into the database itself since most can do auto-increment fields.