aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes help required specifying Transation attributes for this scenario Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "help required specifying Transation attributes for this scenario " Watch "help required specifying Transation attributes for this scenario " New topic
Author

help required specifying Transation attributes for this scenario

harsha av
Greenhorn

Joined: Sep 02, 2004
Posts: 17
Hi ,

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.

Regards,
Harsha

---- 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
.
.
.
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
Should the transaction start and end in Method1? If so, try Required for all the methods called so that Method1's tx propagates into the entity beans.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
harsha av
Greenhorn

Joined: Sep 02, 2004
Posts: 17
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.

Regards,
Harsha
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
Your questions cannot be answered without posting your code and DD.
harsha av
Greenhorn

Joined: Sep 02, 2004
Posts: 17
Thanks for the reply ,

This is the deployment descriptor :

<?xml version="1.0"?>
<!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN' 'http://java.sun.com/dtd/ejb-jar_2_0.dtd'>
<ejb-jar id="ejb-jar_ID">
<enterprise-beans>
<!-- SessionBeans for GIRG10 -->
<session id="AllocationSB">
<ejb-name>StatusSB</ejb-name>
<home>com.test.StatusSBHome</home>
<remote>com.test.StatusSBRemote</remote>
<ejb-class>com.test.StatusSB</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>

<!-- Container Managed Entity Beans for GIRG10 -->
<entity id="StatusCMP">
<ejb-name>StatusCMP</ejb-name>
<home>com.test.StatusCMPHome</home>
<remote>com.test.StatusCMPRemote</remote>
<ejb-class>com.test.StatusCMPBean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>com.test.StatusPK</prim-key-class>
<reentrant>False</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>StatusCMPSchema</abstract-schema-name>
<cmp-field id="CMPAttribute_1119285231651">
<field-name>number</field-name>
</cmp-field>
<cmp-field id="CMPAttribute_1119285595505">
<field-name>typeCode</field-name>
</cmp-field>
<cmp-field id="CMPAttribute_1119330281097">
<field-name>updateTime</field-name>
</cmp-field>
<resource-ref>
<res-ref-name>jdbc/DataSource1</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</entity>

<entity id="EntityCMP">
<ejb-name>EntityCMP</ejb-name>
<home>com.test.EntityCMPHome</home>
<remote>com.test.EntityCMPRemote</remote>
<ejb-class>com.test.EntityCMPBean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>com.test.EntityCMPPK</prim-key-class>
<reentrant>False</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>EntityCMPSchema</abstract-schema-name>
<cmp-field id="CMPAttribute_1119286368017">
<field-name>typeCode</field-name>
</cmp-field>
<cmp-field id="CMPAttribute_1119286371234">
<field-name>entityValue</field-name>
</cmp-field>
<!-- <primkey-field>TypeCode</primkey-field> -->
<resource-ref>
<res-ref-name>jdbc/DataSource1</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</entity>


<!-- Bean managed Entity Beans -->
<entity id="StatusBMPBean">
<ejb-name>StatusBMPBean</ejb-name>
<home>com.test.StatusBMPHome</home>
<remote>com.test.StatusBMPRemote</remote>
<ejb-class>com.test.StatusBMPBean</ejb-class>
<persistence-type>Bean</persistence-type>
<prim-key-class>com.test.StatusPK</prim-key-class>
<reentrant>False</reentrant>
<resource-ref>
<res-ref-name>jdbc/DataSource1</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</entity>

</enterprise-beans>
<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>StatusSB</ejb-name>
<method-intf>Remote</method-intf>
<method-name>updateStatus</method-name>
<method-params>
<method-param>com.test.UpdateData</method-param>
</method-params>
</method>
<method>
<ejb-name>StatusSB</ejb-name>
<method-intf>Remote</method-intf>
<method-name>create</method-name>
<method-params>
<method-param>com.test.CreateData</method-param>
</method-params>
</method>
<method>
<method>
<ejb-name>StatusCMP</ejb-name>
<method-intf>Home</method-intf>
<method-name>create</method-name>
<method-params>
<method-param>int</method-param>
<method-param>java.lang.String</method-param>
<method-param>int</method-param>
<method-param>java.lang.String</method-param>
<method-param>java.sql.Date</method-param>
<method-param>java.lang.String</method-param>
<method-param>java.lang.String</method-param>
</method-params>
</method>
<method>
<ejb-name>EntityCMP</ejb-name>
<method-intf>Remote</method-intf>
<method-name>setEntityValue</method-name>
<method-params>
<method-param>int</method-param>
</method-params>
</method>
<method>
<ejb-name>StatusBMPBean</ejb-name>
<method-intf>Remote</method-intf>
<method-name>updateToHold</method-name>
<method-params>
<method-param>java.lang.String</method-param>
<method-param>java.lang.String</method-param>
</method-params>
</method>
<method>
<ejb-name>StatusBMPBean</ejb-name>
<method-intf>Remote</method-intf>
<method-name>updateToValid</method-name>
<method-params>
<method-param>int</method-param>
<method-param>java.lang.String</method-param>
<method-param>java.lang.String</method-param>
</method-params>
</method>
<method>
<ejb-name>EntityCMP</ejb-name>
<method-intf>Home</method-intf>
<method-name>findByPrimaryKey</method-name>
<method-params>
<method-param>java.lang.String</method-param>
</method-params>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>

</ejb-jar>


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

Could this be because of some connection issue ??

Regards,
Harsha


Status
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
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.
harsha av
Greenhorn

Joined: Sep 02, 2004
Posts: 17
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,
Harsha
harsha av
Greenhorn

Joined: Sep 02, 2004
Posts: 17
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.

Thanks,
Harsha
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: help required specifying Transation attributes for this scenario