Hi everybody,
How can we do Bean Managed Transaction in Stateful Session Bean Using
Weblogic 5.1 .
I am not able to complete the transaction...
Actually i getting null value when i invoke getUserTransaction() method in
the following code. And the operations are not getting roll backed.
If you know anything regarding my problem, please help me out ....
I have written following code ...
ejb-jar.xml :
<ejb-jar>
<enterprise-beans>
<session>
<ejb-name>Trans</ejb-name>
<home>trans.syn.TransHome</home>
<remote>trans.syn.Trans</remote>
<ejb-class>trans.syn.TransEJB</ejb-class>
<session-type>Stateful</session-type>
<transaction-type>Bean</transaction-type>
</session>
</enterprise-beans>
<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>Trans</ejb-name>
<method-intf>Remote</method-intf>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>
</ejb-jar>
weblogic-ejb-jar.xml :
<weblogic-ejb-jar>
<weblogic-enterprise-bean>
<ejb-name>Trans</ejb-name>
<caching-descriptor>
<max-beans-in-free-pool>2</max-beans-in-free-pool>
</caching-descriptor>
<transaction-descriptor>
<trans-timeout-seconds>50</trans-timeout-seconds>
</transaction-descriptor>
<jndi-name>TransSynHome</jndi-name>
</weblogic-enterprise-bean>
</weblogic-ejb-jar>
public class TransEJB implements javax.ejb.SessionBean
{
public void setSessionContext(SessionContext ctx)
{
this.ctx = ctx;
// to do: code goes here.
}
// ---------------------------------------------------------------
// SessionSynchronization interface implementation
public void afterBegin()
{
// to do: code goes here.
}
public void afterCompletion(boolean committed)
{
// to do: code goes here.
}
public void beforeCompletion()
{
// to do: code goes here.
}
// ---------------------------------------------------------------
// create methods
public void ejbCreate()
{
// to do: code goes here.
}
// ---------------------------------------------------------------
// business methods
public void callBusiMethod(int nMemberId, int nAddressNo, String sFirstNam)
{
// to do: code goes here.
Connection con = null;
PreparedStatement stat = null;
try
{
Class.forName("weblogic.jdbc.oci.Driver").newInstance() ;
con = DriverManager.getConnection("jdbc:weblogic:pool:ecogsec",null) ;
stat = con.prepareStatement("INSERT INTO
PTX_ADD(N_MEMBER_ID,N_ADDRESS_NO,S_CONSIGNEE_FIRST_NAM)VALUES(?,?,?)") ;
stat.setInt(1,nMemberId);
stat.setInt(2,nAddressNo);
stat.setString(3,sFirstNam);
tx = ctx.getUserTransaction();
tx.begin();
stat.executeUpdate();
file://tx.commit();
tx.rollback() ;
}
catch(Exception e)
{
System.out.println("Error in creating "+e.toString() );
}
finally
{
try
{
tx = null ;
if(stat != null)
stat.close();
}
catch(Exception e)
{
}
try
{
if(con != null)
con.close();
}
catch(Exception e)
{
}
}
}
// ---------------------------------------------------------------
// private fields
private SessionContext ctx;
private javax.transaction.UserTransaction tx ;
}
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".