Deleted Entity, Which MDB

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).

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.

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

Posts: 27

posted 13 years ago

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?

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.

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.

SCJP 1.4, SCWCD 1.3, SCBCD 1.3

Mohana Murali

Greenhorn

Posts: 27

posted 13 years ago

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

Posts: 1683

posted 13 years ago

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.