Hi:
Thanks.
In JBoss documentation ch08s63.html clearely says too:
"EJB's can either use declarative transaction management specified in the ejb-jar.jar
xml descriptor, or programmatic transaction manager using the UserTransaction
interface. Either way, the transaction services are provided by the application
server. "
But we have use this in Weblogic 5.1 & 6.0.
There we definded our SessionBean to be a Stateless Bean that requires a container
transaction.
And this Sessionbean may call a BMP EntityBean that was defined to be Transaction
required.
Then in our JSP, we can use an UserTransaction to act like the way we want.
Below is part of the JSP code that arraise a Transaction in Weblogic 5.1 & 6.0.
public static UserTransaction getTransaction() throws NamingException
{
UserTransaction tx = null;
javax.naming.Context ctx = null;
try {
ctx = getInitialContext();
if( ctx != null){
tx = (javax.transaction.UserTransaction)
ctx.lookup("javax.transaction.UserTransaction");
}else{
throw new NamingException();
}
} catch (Exception e) {
e.printStackTrace();
}
}
...
UserTransaction tx = (javax.transaction.UserTransaction) getTransaction();
try {
tx.begin();
...
} catch (Exception e) {
tx.rollback();
}
And it really works well.
Below is the ejb-jar.xml for EntityBean:
<?xml version="1.0"?>
<!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN'
'http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd'>
<ejb-jar>
<enterprise-beans>
<entity>
<ejb-name>zee120BeanHome</ejb-name>
<home>cn.com.MSTMT.Entity.zee120.zee120BeanHome</home>
<remote>cn.com.MSTMT.Entity.zee120.zee120</remote>
<ejb-class>cn.com.MSTMT.Entity.zee120.zee120Bean</ejb-class>
<persistence-type>Bean</persistence-type>
<prim-key-class>cn.com.MSTMT.Entity.zee120.zee120BeanPK</prim-key-class>
<reentrant>False</reentrant>
</entity>
</enterprise-beans>
<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>zee120BeanHome</ejb-name>
<method-intf>Remote</method-intf>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>
</ejb-jar>
Below is for SessionBean:
<?xml version="1.0"?>
<!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN'
'http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd'>
<ejb-jar>
<enterprise-beans>
<session>
<ejb-name>zes120BeanHome</ejb-name>
<home>cn.com.MSTMT.Session.zes120.zes120BeanHome</home>
<remote>cn.com.MSTMT.Session.zes120.zes120</remote>
<ejb-class>cn.com.MSTMT.Session.zes120.zes120Bean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>zes120BeanHome</ejb-name>
<method-intf>Remote</method-intf>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>
</ejb-jar>
May someone give a hint? thanks a lot.
----- Original Message -----
From: "Ole Husgaard" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, July 12, 2001 5:44 AM
Subject: Re: [JBoss-user] Urgent, May someone tell me how JBoss realize a Transaction?
> Hi,
>
> Please note that you go beyond the spec if you
> try to marcate transaction boundaries from an
> entity bean.
> EJB1.1, section 11.6.1 clearly says: "A Bean
> Provider is not allowed to provide an Entity
> bean with bean-managed transaction demarcation."
> (EJB2.0 draft says that it is allowed for
> message beans too.)
>
> So basically you are on your own if you want
> to do this: No EJB conforming container can
> support it.
>
>
> Best Regards,
>
> Ole Husgaard.
>
>
> > Edward Wang wrote:
> >
> > Now I am using JBoss+Tomcat 2.22 pack.
> >
> > I setup a Datasource that connect to SQLServer 7.0 with the JDBC Driver of
>WebLogic (BEA Sys, a Type 4 Driver).
> > And in my Client Class that calls an EJB (Entity), I use the
>"javax.transaction.UserTransaction", it seems JBoss
> > can not find the name in it's Context. Then I use a TxManager class in the
>following way:
> >
> > TxManager tx = null;
> >
> > try {
> > tx = org.jboss.tm.TxManager.getInstance();
> > tx.begin();
> >
> > zee120Beanhome home = getHome();
> > zee120BeanPK pk = new zee120BeanPK("001");
> > zee120 cli = home.findByPK(pk);
> >
> > cli.remove();
> >
> > tx.commit();
> > } catch (Exception e) {
> > tx.rollback();
> > }
> >
> > The record "001" is expected to exist in my DB still if some error occurs, but the
>result is it was removed.
> >
> > How can I use Transaction with JBoss?
> >
> > Thanks for your help.
> >
> >
> >
>
> _______________________________________________
> JBoss-user mailing list
> [EMAIL PROTECTED]
> http://lists.sourceforge.net/lists/listinfo/jboss-user
>
�,�ǫ����x%��I�,�ǫ�+-��.�ǟ����a���X���(��~��zw��X�����b��?��,��