12 Replies Latest reply on Oct 20, 2003 9:53 PM by Sreeni Janapati

    How to delete multiple records (entity beans)?

    song chang Newbie


      I am not sure what is the best way to delete multiple records from database through CMP.

      Assuming I have a entity bean Customer which has the following structure.
      id int (primary key)
      firstName String (non unique)
      lastName String

      In the home interface, I have a findByFirstName() which returns a collection. How do I delete those entity beans which has firstName="TOM"? In sql, I could do "delete customer where firstname='TOM'. In EJB, I am doing something like this:

      Collection c = home.findByFirstName().
      Go through each element in the collection and call remove().

      This works. However the server log shows a delete statement for every record which has firstname="TOM". I guess this mean JBoss has to go to database many times. Is there an alternative in addition to using direct JDBC?

      If I use c.clear(), should this delete all the records from database? I tried this, it doesn't work.

      Your comments are appreciated.