RE: Re: Destroy an Entity Bean

Rajeev Dave <[email protected]> Mon, 8 Apr 2002 17:35:55 +0530
Newsgroups gmane.comp.java.ejb.general
Message-ID <342F6DED4DF4D511AA5A00B0D079FEE3A48B42@MAYA>
Hi Sudesh,
I am kind of skeptical about what you iterated.
These callbacks are at best, left to be called by the container. 

Since the set/unsetEnityContext are not exposed by any of interfaces, that
itself gives an indication that you are not supposed to meddle around by
calling these methods. 

Supposing you call unsetEntityContext, the call to these methods will have
to be from inside the bean implementation code and container might not get a
chance to do its cleanup part for that bean.

<javadoc>

public void unsetEntityContext()
                        throws EJBException,
                               java.rmi.RemoteException 
Unset the associated entity context. The container calls this method before
removing the instance. 

This is the last method that the container invokes on the instance. The Java
garbage collector will eventually invoke the finalize() method on the
instance. 

This method is called in an unspecified transaction context.

Throws:

EJBException - Thrown by the method to indicate a failure caused by a
system-level error.
java.rmi.RemoteException - This exception is defined in the method signature
to provide backward compatibility for enterprise beans written for the EJB
1.0 specification. Enterprise beans written for the EJB 1.1 and higher
specification should throw the javax.ejb.EJBException instead of this
exception.

</javadoc>


Peace,
Rajeev Dave


-----Original Message-----
From: sudesh kumar [mailto:[email protected]]
Sent: Friday, April 05, 2002 1:01 PM
To: [email protected]
Subject: RE: [EJB-Developer] Re: Destroy an Entity Bean


The best way to destroy the instance of the entity
bean ( not the bean itself) is to use
unsetEntityContext() method

Sudesh
 
--- Rajeev Dave <[email protected]> wrote: > If
you want to destroy the --instance-- of the bean,
> 
> have a method inside the bean(lets say
> destroyBean()) 
> and simply throw RemoteException (or any non
> application exception)
> inside the method. If the appserver is
> "ejb-compliant",
> it should destroy that instance.
> 
> But here you need to judge on transaction boundries
> and 
> all related complexities involved.
> 
> HTH
> 
> -Rajeev Dave
> 
> 
> --- In EJB-Developer@y..., Nicolas D'Ippolito
> <mr_dipi@y...> wrote:
> > Hi, I have a problem with the Entity Bean. I need
> to
> > know how to destroy an EJB, because remove method
> > seems to destroy a row from the associated table
> > (apparently it needs a key column).
> > 
> > I hope you can help me. Thanks.