File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes How to update row in CMP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "How to update row in CMP" Watch "How to update row in CMP" New topic
Author

How to update row in CMP

Sri Rangan
Ranch Hand

Joined: Dec 08, 2001
Posts: 160
I am using a Entity Bean CMP (assocuated with one table) which is called by a session bean.
CMP Entity Bean remote Interface has the get/set methods for the data need to be updated in the table.
From the session bean, I get the Entity Bean Home by look up and calling the findByPrimaryKey(KeyObject) and it returns the Remote.
Now my requirement is to update a few fields in the row which I get by the findByPrimaryKey(keyObject). How should I update the row?

I know the create() will call ejbCreate() and insert into... SQL will be called. How does the container know that it has to call the update .... SQL for this row.
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
I'd suggest you read the EJB Spec, or better yet, read any of the dozens of books on EJB's. They all cover this process in detail.
What happens is that when the transaction ends that the new data (set using setter methods in the Entity bean) is written to the database with an UPDATE statement.
As to how it knows -- the simplest approach (which every container supports) is to simply write back ALL of the data from all of the EJB's used in the transaction with UPDATE statements. Smarter approaches use "dirty" flags to decide if any of the data has been changed (thus reducing the number of UPDATE statements). Only some containers support dirty flags
Kyle
------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.
[This message has been edited by Kyle Brown (edited January 01, 2002).]


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to update row in CMP