cancel
Showing results for 
Search instead for 
Did you mean: 

Delete method for entity beans

Former Member
0 Kudos

Hello experts

I have created entity and session beans to conduct database transactions. My database table has the following fields

room_id -- string

room_name -- String

For the entity bean RoomsBean, the default methods ejbCreate(String a, String b) and ejbfindbyPrimaryKey(String a) are created that I uase to create a record in the database and find a record in the database.

Now, I need a method to delete records from databse. How do I create that method? Is there a default method that I can use to delete a record? Do I have to create a method and use EJB QL to do it?

If I have to create a method, then where do I create it as the options under ejb methods are

1. create methods

2. find methods

3. home methods

4. select methods

please help.

Accepted Solutions (0)

Answers (2)

Answers (2)

Vlado
Advisor
Advisor
0 Kudos

Hi Sabbir,

From your question I assume you are using CMP entity beans. In this case you don't need to do anything in the entity bean coding. In the session bean just call the <b>remove()</b> method on the entity home or component interface -- the container will do all the work for you. (These methods are available for every entity bean - they are defined on the javax.ejb.{EJBLocalObject | EJBObject | EJBLocalHome | EJBHome} interfaces.)

If you are using BMP, all you have to do is to implement the <b>ejbRemove()</b> method in the bean class (this method is inherited from the javax.ejb.EntityBean interface).

Hope it helps!

-Vladimir

praveenkumar_kadi
Active Contributor
0 Kudos

Hi,

Here is an <a href="http://www.javapassion.com/j2ee/EntityBean.pdf">pdf</a> for your all your ejb related issues.

How ever, in short I can say, there are methods in entity bean to create, remove a record from table. check the above pdf for piece of code especially 79 and 103 for creating and removing a record.

<a href="http://www.javapassion.com/j2ee/EntityBean.pdf">Create and Remove</a>

Reward points it it helps