aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Problem in Transaction Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Problem in Transaction" Watch "Problem in Transaction" New topic
Author

Problem in Transaction

sachin sachdeva
Greenhorn

Joined: Mar 13, 2001
Posts: 14
Hi To all
I was trying to test some basics on Transactions but i did not get any relevent output.
my Bean code

public void one() throws Exception
{
for(int i=1;i<=10;i++) Trans Att Required
{
pstmt.setInt(1,i);
pstmt.executeUpdate();
}
two();
three();
}
public void two() throws Exception Trans Att RequiresNew
{
for(int i=11;i<=20;i++)
{
pstmt.setInt(1,i);
pstmt.executeUpdate();
}
}

public void three() throws Exception
{ Trans Att Never
for(int i=21;i<=30;i++)
{
pstmt.setInt(1,i);
pstmt.executeUpdate();
Thread.sleep(50000);
}
}

jar File
<ejb-jar>
<enterprise-beans>
<session>
<ejb-name>TransBean</ejb-name>
<home>Trans.TransHome</home>
<remote>Trans.TransRemote</remote>
<ejb-class>Trans.TransBean</ejb-class>
<session-type>Stateful</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>TransBean</ejb-name>
<method-intf>Remote</method-intf>
<method-name>one</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
<container-transaction>
<method>
<ejb-name>TransBean</ejb-name>
<method-intf>Remote</method-intf>
<method-name>two</method-name>
</method>
<trans-attribute>RequiresNew</trans-attribute>
</container-transaction>
<container-transaction>
<method>
<ejb-name>TransBean</ejb-name>
<method-intf>Remote</method-intf>
<method-name>three</method-name>
</method>
<trans-attribute>Never</trans-attribute>
</container-transaction>
</assembly-descriptor>
</ejb-jar>

Output
ouput is 1-30 in database
whereas i think it shuld be 1-20 after that TransactionNotSupportedException

Madhu Juneja
Ranch Hand

Joined: Mar 10, 2001
Posts: 176
Page 196 (marked as 192) of ejb 1.1 specs mentions that the client's view and the container's action as follows :
Client's View
Receives RemoteExcep-tion. If the client executes in a transaction, the client´┐Żs transaction is not marked for rollback, and client can continue its work.
Container's action
with the NotSup-ported, Never, and Supports attributes.
error.
Discard instance.
Throw RemoteException.

Also O'reilly 2nd ed mentions that the container handles system exception where as Application exceptions are to be handled by the bean provider (as far as I remember. I will post on this tomorrow).
Hence you put the logic of three method in a try block and in the catch block, rethrow EJBException. This rethrown exception is now handled by the container (my understanding! ). Then the output may be as per your understanding.
HTH

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in Transaction