hello 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
To remove records from entity bean call ejbObject.remove() where ejbObject is the remote object reference for the given entity bean data instance
Joined: Jan 14, 2002
hello 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!
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 key.so that,i must implement delete function in my project by TWO steps-find and remove.and connect database TWICE.it 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.
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.