Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Entity Bean - BMP - Transaction  RSS feed

 
Anurag Gupta
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whether to perform commit/rollback programatically for persistance code in a Bean Managed Persistance for an Entity Bean?
  • Entity Bean - BMP: We need to provide logic for persistance to a Database.
  • Entity Bean - HAS to have Container Managed Transaction (atleast for the Remote Business Methods).

  • Following is a pseudo code. What should be done at the question marks?
     
    Roger Chung-Wee
    Ranch Hand
    Posts: 1683
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    If you use JDBC transactions in your BMP bean, then the usual rules apply. So, you would disable auto-commit is if makes sense and then explicitly commit after the insert. And don't forget to close the Connection.

    However, do not get physical connections - I don't like doing this at all. It is best to get logical connections by obtaining your connections from the pool via the DataSource.

    You must declare transaction attributes for the create, remove and business methods declared in the bean's interfaces. The container will run the methods in the appropriate transactions. Here is a summary.
    The ejbCreate and ejbRemove methods run in the transaction context of the matching create and remove methods.

    The ejbLoad method will run in the transaction context determined by the transaction attribute of the business method that triggered the ejbLoad method.

    The ejbStore method will run in the same transaction context as the previously invoked ejbLoad or ejbCreate method.
    So, if the create method has a trans attribute of Required, then ejbCreate will run in a transaction.

    On another subject: never declare RemoteException in a method in the bean class as it is a violation of the spec.
     
    Don't get me started about those stupid light bulbs.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!