• Post Reply Bookmark Topic Watch Topic
  • New Topic

Aborting the client's remove() call  RSS feed

 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If i have a CMP entity bean and want to put in checking before allowing the client's remove() to delete it, can I put the checking in ejbRemove()? And if yes, how do I tell the container not to proceed with the remove? I just dont want to abort the whole txn so will not call setRollbackOnly(). Can throwing RemoveException in ejbRemove() achieve this?
 
Alex Sharkoff
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alec,

Yes, you can throw javax.ejb.RemoveException from an ejbRemove() method in order to indicate to the container that an application error has occurred in entity object's removal process. Container gets RemoveException and simply sends it to the client without performing the rollback (this is the behaviour with all application exception).

That is what the spec says about javax.ejb.RemoveException in entity bean:

10.5.8.5 RemoveException
From the client´┐Żs perspective, a RemoveException (or a subclass of RemoveException) indicates that an application level error occurred during a remove(...) operation. If a client receives this exception, the client does not know, in general, whether the entity object was removed or not. The client also does not know if the transaction has been marked for rollback. (However, the client may determine the transaction status using the UserTransaction interface.)

The Container or Bean Provider throws the RemoveException (or subclass of RemoveException) from a remove method to indicate an application-level error from the entity object removal operation. Optionally, the Container or Bean Provider may mark the transaction for rollback before throwing
this exception.

The Container or Bean Provider is encouraged to mark the transaction for rollback only if data integrity would be lost if the transaction were committed by the client. Typically, when a RemoveException is thrown, it leaves the database in a consistent state, allowing the client to recover.
The Container treats the RemoveException as any other application exception. See Section 18.3.


Hope it helps
 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alex,

Thx for the reply.

But if I dont want the txn to be marked for rollback, can RemoveException be used in ejbRemove() as an indicator so that the container will not proceed to removing the row in db?

The spec does say that the next step after ejbRemove() that the CMP container will do is to remove the physical row in the db.

What I understand from the quoted paragraph, it doesn't say RemoveException is such an indicator between **CMP bean class and container**. It only tell the **client** the RemoveException could mean db not physically deleted.

Alec
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!