aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Deleted Entity, Which MDB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Deleted Entity, Which MDB" Watch "Deleted Entity, Which MDB" New topic
Author

Deleted Entity, Which MDB

Mohana Murali
Greenhorn

Joined: Sep 26, 2002
Posts: 27
Hi,

1)What happens to Entity bean if we running application and delete the row(whose entity bean is active) from backend database manuvally. Does Entity bean throw Object not found exception? Does Entity bean keep the state of Entity bean?


2)How does MDB know the incoming message is belong to it and consumes it? How does other MDB does not consume it. (Assume message type is same for all implemented MDBs).

I keep getting above interview questions, I am not sure I am right.

Thanks in advance,
Mohana
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704
Hi Mohana,


1)What happens to Entity bean if we running application and delete the row(whose entity bean is active) from backend database manuvally. Does Entity bean throw Object not found exception? Does Entity bean keep the state of Entity bean?

Accordingly to J2EE specs, every transaction starts with invoking ejbLoad() and ends with calling ejbStore(). Hence if the row is removed manually from the database the ejb container is still consistent with the database and no exception is thrown. The huge drawback of this silly approach is that ejb data cannot be cached between transactions and the container reloads the data every time a transaction is started. However some containers like weblogic have special concurrency strategies that allow caching the data using an optimistic approach.

2)How does MDB know the incoming message is belong to it and consumes it? How does other MDB does not consume it. (Assume message type is same for all implemented MDBs).

Not sure if I understand the question, but every MDB acts like a listener to a Topic or Queue. Is the JMS service that knows how to deliver messages to the right recipient, etc.
Regards.


I think, therefore I exist -- Rene Descartes
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
What happens to Entity bean if we running application and delete the row(whose entity bean is active) from backend database manuvally.

This cannot happen if the bean is in a transaction. After invoking ejbActivate, the container starts a transaction and tells the DB to lock the row to anyone else but the Container. Only after the transaction ends will the container tell the DB to release the row lock.


How does MDB know the incoming message is belong to it and consumes it? How does other MDB does not consume it.

The relationship between a destination and the MDBs are declared in the DD. So, a queue type will have an MDB type associated with it.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Mohana Murali
Greenhorn

Joined: Sep 26, 2002
Posts: 27
Thanks for the answers.

1) I am still not clear about it. I was asked in inteview about it. I do informed that, you can not delete record since it was locked by container. But they told me to assume that "record can be deleted from DB" and explain the consequences. I said, container throws SystemException. Is it not true? It looks like container can not able to find the row it is about to update just after transaction and not able to find it. So it's a irrecoverable system erorr?!!!

Well I got same question in another interview. I said, container throws ObjectNotFound exception, Thinking that it should be application exception and developer suppose to catch it in every entity bean. May be I was wrong in both answers.

So I am not sure which is the correct answere for it.

2) DD can be configured to make sure, MDB receives the expected message. Do we still need correction ID concept to be complete solution? if not when do we need correction IDs also?
Nadeem Awad
Ranch Hand

Joined: Jan 09, 2005
Posts: 74

What happens to Entity bean if we running application and delete the row(whose entity bean is active) from backend database manuvally.


Dear Mohana,
Check out the EJB 2.0 Specs Page 374:

18.2.2.1 javax.ejb.NoSuchEntityException
The NoSuchEntityException is a subclass of EJBException. It should be thrown by the entity bean class methods to indicate that the underlying entity has been removed from the database.
An entity bean class typically throws this exception from the ejbLoad and ejbStore methods, and from the methods that implement the business methods defined in the component interface.


and Page 379:

18.3.4 javax.ejb.NoSuchEntityException
The NoSuchEntityException is a subclass of EJBException. If it is thrown by a method of an entity bean class, the Container must handle the exception using the rules for EJBException described in Sections 18.3.1, 18.3.2, and 18.3.3.


Share Knowledge to gain it.<br /> <br />SCJP 1.2, SCDJWS 1.4, SCWCD 1.4, SCBCD 1.3, ICAD
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
DD can be configured to make sure, MDB receives the expected message. Do we still need correction ID concept to be complete solution? if not when do we need correction IDs also?

I have never heard of a "correction ID". If you mean "connection ID", this refers to the configuration of a durable topic subscription for an MDB that is deployed to a cluster. The connection ID is the ClientId for the JMS Connection Factory, and is unique within a cluster.
Mohana Murali
Greenhorn

Joined: Sep 26, 2002
Posts: 27
Thanks Nadeem, So it always SystemException(NoSuchEntityException).

Roger, I meant Correlation ID not connection ID, My question was incorrect. Does Correlation ID used for synchronous communication using JMS?
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
In an asynchronous JMS service, the correlation ID is imbedded in the response message in order to correlate an asynchronous reply with a message that was sent at an earlier time.

In a synchronous JMS service, the sender blocks and waits for a response from the recipient, so correlation is not needed.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Deleted Entity, Which MDB