I am trying to create/update rows in a database using BMP and CMP beans. A business method ( Method1 )in session bean calls a non-business method ( Method2) in the same session bean which inturn calls an EntityBean ( EB1-BMP) . EB1 can throw a certain business exception upon which , the Method1 in the session bean calls another EntityBean in a loop( EB2-CMP). The problem is that , when the EB1 throws the business exception, i am getting an exception ( part of the stack trace attached below ). Could any please explain what should be the transaction attributes to be specified for this scenario. Using RequiresNew for the EntityBeans would not work ( or would it ?? ) because the entity bean is being called in a loop and the commit or rollback should happen for all the methods. I feel the problem should be solved by specifying the transaction attribute for Method2 ( non business method in session bean ) as Required, but i guess this is not possible. Could someone please suggest a solution or workaround for this problem.
---- Begin backtrace for nested exception java.lang.IllegalStateException at com.ibm.ws.Transaction.JTA.TransactionImpl.enlistResource(TransactionImpl.java:1694) . . . javax.ejb.EJBException: nested exception is: com.ibm.ws.ejbpersistence.utilpm.PersistenceManagerException: PMGR6022E: Error using adapter to create or execute an Interaction. com.ibm.ws.rsadapter.cci.WSInteractionImpl@28d16547 . . .
The problem occurs while using the Required transaction attribute.
Actually, the calls to EB1-BMP and EB2-CMP are sort of independent that is to say, if the specified business exception is thrown ( from EB1-BMP, finder method) then i call EB2-CMP in a loop ( creating records ), if the exception is not thrown, then i call a different business method in EB1-BMP ( updating records ). When the exception is thrown from EB1 finder method , i am trying to call EB2-CMP , this is where is exception is being thrown.
Can it be because of some connection re-use. what happens to the transaction or the connection at the point where the exception is thrown from EB1.
Here, StatusSB calls StatusBMP.findByStatus( ) method which throws a business exception. StatusSB then calls StatusCMP.create( ) in a loop to create the records. If exception is not thrown , StatusBMP.updateTo<status>() method is called in a loop. The problem is occuring when the StatusCMP's methods are invoked, specifically, from the stack trace, in the findByPrimaryKey (where probably the container is trying to get a connection).
Your DD does not look right to me. If you fail to write the <trans-attribute> elements for the methods, some EJB containers will make assumptions. But what are those assumptions? I can't tell, so be explicit with your <trans-attribute> elements.
Also, for the findByPrimaryKey method you have this.
You do not need a transaction for a finder or a search method, so you can try NotSupported instead.
If there was a failure to obtain a connection, SQLException would be thrown, so I don't think that's the problem.
Post your code so that we can get a better idea as to what's going wrong.
The DD has been created using WSAD, the transaction attribute is shown as Required for all the methods only once for all methods . Are you suggesting that I add the entry manually for each of the methods. I can post the code only by tommorrow.
Thanks a lot for suggesting to use the NotSupported attribute for the finder method. The code is working now
1) Strangely though, what i noticed was that, when the exception was thrown from the finder method and i made a call to the CMP bean, the call was failing at the CMP's findByPrimaryKey method ( dont know why !!) but a call to the findByPrimaryKey method of the BMP of the same enity was working fine!! Any pointers to why this could happen is greatly appreciated.
2) Also, I remember not associating any transaction with the finder methods before I tried using Required for the finder methods , but it seemed to give the same exception , ( I might have overlooked something at that point of time - not sure ). Is it possible that an exception of this sort could happen even if no transaction is associated with the finder methods ??
Awaiting your response as to why this could happen.
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop