Meaningless Drivel is fun!*
The moose likes EJB and other Java EE Technologies and the fly likes how to delete database records 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 delete database records in cmp? " Watch "how to delete database records in cmp? " New topic
Author

how to delete database records in cmp?

Mike Lin
Ranch Hand

Joined: Oct 29, 2002
Posts: 48
How can I delete or update records in CMP .
EJB-QL just able to 'SELECT' OBJECT .Will EJB-QL be update to able to UPDATE or DELETE OBJECT?

If I write some SQL in EJBRemove(),Will CMP lose its advantage of Container Managed?
thank u ~~~~~~~~~~~


SCJP1.4 <br />Best wishes!<br />中国人!
Sergiu Truta
Ranch Hand

Joined: Dec 16, 2003
Posts: 121
You can delete records using remove from the home interface like
entityHome.remove(primaryKey);
or you can lookup for the local/remote interface and call remove:
entityLocal = entityHome.findByPrimaryKey(primaryKey);
entityLocal.remove();
Updating records in CMP is done by updating the CMP fields using the set methods.
That's the idea behind the CMP (RAD - Rapid Application Development).
If you wanna write your own UPDADE/DELETE SQL statements, you can use BMP or Session Beans with JDBC.
Sergiu.


...watch me...as I'm walking the path...
Vishwa Kumba
Ranch Hand

Joined: Aug 27, 2003
Posts: 1064
EJB-QL is EJB-Query language.....
Only for querying data. No insert/delete/update stmts.
It would be a bad design to mix CMP and BMP code in an entity bean.
In a CMP, the container is responsible to delete your data from the database.We do not have to write any delete stmts in the ejbRemove() method.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to delete database records in cmp?