Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

delete a record from db

 
zb cong
Ranch Hand
Posts: 416
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
AmitKumar Verma
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 416
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If "Tom" is the primary key, you can use EJBHome#remove(Object primaryKey) for just that purpose.
 
zb cong
Ranch Hand
Posts: 416
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic