Showing posts with label Java Interview Question and Java Beginner Tutorial - Part 3. Show all posts
Showing posts with label Java Interview Question and Java Beginner Tutorial - Part 3. Show all posts

Thursday, January 19, 2012

Java Interview Question and Java Beginner Tutorial - Part 5

I am developing a BMP Entity bean. I have noticed that whenever the create method is invoked, the ejbLoad() and the ejbStore() methods are also invoked. I feel that once my database insert is done, having to do a select and update SQL queries is major overhead. is this behavior typical of all EJB containers? Is there any way to suppress these invocations?

This is the default behaviour for EJB. The specification states that ejbLoad() will be called before every transaction and ejbStore() after every transaction. Each Vendor has optimizations, which are proprietary for this scenario.

    Java Interview Question and Java Beginner Tutorial - Part 4

    Is there any way to force an Entity Bean to store itself to the db? I don’t wanna wait for the container to update the db, I want to do it NOW! Is it possible?

     Specify the transaction attribute of the bean as RequiresNew. Then as per section 11.6.2.4 of the EJB v 1.1 spec EJB container automatically starts a new transaction before the method call. The container also performs the commit protocol before the method result is sent to the client.

      Java Interview Question and Java Beginner Tutorial - Part 3

      Is it possible to specify multiple JNDI names when deploying an EJB?

      No. To achieve this you have to deploy your EJB multiple times each specifying a different JNDI name.