File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes delete a record from db Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "delete a record from db" Watch "delete a record from db" New topic

delete a record from db

zb cong
Ranch Hand

Joined: Jan 14, 2002
Posts: 416
i want to use the entity bean to operate the datebase,i can insert a record by "create" method,and modify a record by "finder" and "set" method,but i don't know how can i delete a record from database by using entity bean,who can help me?
thank you
AmitKumar Verma

Joined: Jul 30, 2003
Posts: 2
To remove records from entity bean call ejbObject.remove() where
ejbObject is the remote object reference for the given entity bean data instance
zb cong
Ranch Hand

Joined: Jan 14, 2002
Posts: 416
thanks for your helps
yes,i have found two "remove" method,one in "EJBLocalHome"(remove(Object primaryKey)),other is in the "EJBLocalObject"(remove()),i don't know how to use them.and i think both of them are inconvenient,such as i want to implement following function:
delete from student where the name="Tom"
if i use the two mentioned method,i must do it by two step i guess:
1 use the finder method to find the student named "tom".
2 use the remove method to delete it.
i wonder if i can add a customerized "remove" method,such as "remove(sting name)" to delete it in ONE step?
thank you!
Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962
If "Tom" is the primary key, you can use EJBHome#remove(Object primaryKey) for just that purpose.

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
zb cong
Ranch Hand

Joined: Jan 14, 2002
Posts: 416
no,the tom is not the pk.what i just concern is if i can write the CUSTOMERIED remove method,just like the finder method(i can use the ejb-ql),because the entity bean only provide us one remove method-"remove(Object pk)",it's not convenient.if fact,in my progam,i NEVER delete record by primary that,i must implement delete function in my project by TWO steps-find and remove.and connect database is not performent.if i use the jdbc,i only connect db once,and send the sql clause(delete from........)to it,then it done.
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8927

There is no EJBQL for remove methods.
I think you can have a ejbhome that takes customer id, which in that calls
ejbselect (here u can u use EJB QL) and once you get the entity you can the remove method. This is a 2 step process too but it is hidden from the client.

I agree. Here's the link:
subject: delete a record from db
It's not a secret anymore!