In the deployment descriptor XML file you can assign transaction attributes
to methods.  The simplest way to handle this if you are calling the entity
beans methods from a session bean is to set the method on the session bean
to have the transaction attribute required, and the  entity bean methods to
also use required.  This will have the effect of starting a transaction
right before the session bean's method begins to execute and completing the
transaction right after the session bean's method completes.  This is known
as Container managed transactions (CMT) which is easier to use than Bean
managed transactions (BMT) which is where you would lookup a UserTransaction
object and manage the transaction in your code.

The transaction attributes go at the end of the ejb-jar.xml file in a part
called the assembly descriptor...  Something like this...

<ejb-jar>
    <enterprise-beans>
       <entity>
            <description>Category bean</description>
            <ejb-name>cd.Category</ejb-name>
...
     </enterprise-beans>
    <assembly-descriptor>
        <container-transaction>
            <method>
                <ejb-name>cd.Category</ejb-name>
                <method-name>*</method-name>
            </method>
            <trans-attribute>Required</trans-attribute>
        </container-transaction>
...
</ejb-jar>

Cheers
Jay

-----Original Message-----
From: Nimmons, Buster [mailto:[EMAIL PROTECTED]]
Sent: Thursday, May 10, 2001 2:40 PM
To: [EMAIL PROTECTED]
Subject: Re: Placing entinty bean data back in storage


Ok that makes sense, so if I have a session bean performing a setField()
Method (or multiple setField() methods depending on business logic) on an
etity bean then I should
enclose it in a transaction clause to perform the DB update?

-----Original Message-----
From: Jay Walters [mailto:[EMAIL PROTECTED]]
Sent: Thursday, May 10, 2001 1:15 PM
To: [EMAIL PROTECTED]
Subject: Re: Placing entinty bean data back in storage


This is a very good question.  Much of the value in using entity beans is
the fact that as a developer you need only write the methods to load and
store the bean and the container will manage calling them at the proper
times.  Of course there is the caveat that one needs to choose the proper
transaction attributes.

That being said, one ensures the changes are properly stored in the database
by making the changes to the entity bean within a transaction.  Given this,
the container will take care of the rest.

Cheers
Jay

-----Original Message-----
From: Nimmons, Buster [mailto:[EMAIL PROTECTED]]
Sent: Thursday, May 10, 2001 1:26 PM
To: [EMAIL PROTECTED]
Subject: Placing entinty bean data back in storage


> After recently completing my first Entity bean assignment in which I
> called home.create() to create a data object both in my database and in
> the entity bean, I noticed that at the end of the lesson we had to call
> home.remove() which not only removed the data from the in-memory entity
> bean but also from the database. According to my experience removing
> database data is not done nearly as often as creating data. However on an
> EJB home object there is no save() method or anything like that. Are we
> simply to rely on the EJB container to call the EJBs store method whenever
> it deems it necessary. How do we assure that changes made to entity bean
> data gets saved to the database.

===========================================================================
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".

===========================================================================
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".

===========================================================================
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".

===========================================================================
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".

Reply via email to