Exforsys

Online Training

Answer EJB Interview Questions - Part 1

This is a discussion on Answer EJB Interview Questions - Part 1 within the Java Tutorials forums, part of the Articles and Tutorials category; We are in the process of preparing answers for the interview questions from our question bank . Please anser the following ...


Go Back   Exforsys > Articles and Tutorials > Java Tutorials

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-30-2004, 02:48 PM
Senior Member
 
Join Date: Nov 2004
Posts: 175
sanereddy is an unknown quantity at this point
Answer EJB Interview Questions - Part 1

We are in the process of preparing answers for the interview questions from our question bank . Please anser the following questions with any reference links for any sample code, tutorial or ebook chapter. After we get answers for these questions, we will update the question bank and move on to the next set of questions.

1. Is there a way to get the original exception object from inside a nested or wrapped Exception (for example an EJBException or RemoteException)

2 If my session bean with single method insert record into 2 entity beans, how can I know that the process is done in same transaction (the attributes for these beans are Required)

3 What is EJB architecture(components)

4 How can i retrieve from inside my Bean(Stateless session and Entity CMP) the user name which i am serving (the user name of user just logged in my web application)

5 Can I develop an Entity Bean without implementing the create() method in the home interface

6 Is stateless Sessiob bean create() method contains any parameters

7 What is the difference between ejbCreate() and ejbPostCreate()

8 What is the difference between ejbStore() and ejbLoad()

9 With EJB 1.1 specs, why is unsetSessionContext() not provided in Session Beans, like unsetEntityContext() in Entity Beans

10 Why are ejbActivate() and ejb Passivate() included for stateless session bean even though they are never required as it is nonconversational bean
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 09-30-2004, 10:19 PM
Senior Member
 
Join Date: Nov 2004
Posts: 132
Vasu
Re:Answer EJB Interview Questions - Part 1

Quote:
Why are ejbActivate() and ejb Passivate() included for stateless session bean even though they are never required as it is nonconversational bean
To have a consistent interface, so that there is no different interface that you need to implement for Stateful Session Bean and Stateless Session Bean.
Both Stateless and Stateful Session Bean implement javax.ejb.SessionBean and this would not be possible if stateless session bean is to remove ejbActivate and ejbPassivate from the interface. You could argue that the two (stateful and stateless) are so different that they should have their own interface but Sun did not think so. They made both session beans implement the same interface and provided deployment descriptor to denote which one is it that you are deploying.

Quote:
With EJB 1.1 specs, why is unsetSessionContext() not provided in Session Beans, like unsetEntityContext() in Entity Beans
ejbRemove() is called for session beans every time the container destroyes the bean. So you can use this method to do the stuff you typically would do in unsetEntityContext(). For entity beans ejbRemove() is only called if the user explicitly deletes the bean. I think that is the reason why the engineers at SUN invented the unsetEntityContext() for this kind of bean.

Quote:
If my session bean with single method insert record into 2 entity beans, how can know that the process is done in same transaction (the attributes for these beans are Required)?
If your method in the session bean is already running under a transaction the calls to any other bean which have been deployed with trans-attribute \'Required\' will be executed within the same transaction context.
So if your session bean is using container-managed transactions and your method is deployed with \'Required\', \'RequiresNew\' or \'Mandatory\', you can safely assume that the calls to your entity beans are handled under same transaction. If you\'re not running in a transaction, a separate transaction will be set up for each call to your entity beans.
If your session bean is using bean-managed transactions, you can ensure that the calls are handled in the same transaction by :
javax.transaction.UserTransaction tran= null;
try{
tran=ctx.getUserTransaction();
tran.begin();
myBeanHome1.create(....);
myBeanHome2.create(...);
tran.commit();
}catch(...){}
You may want to check if you\'re already running in a transaction by calling tran.getStatus().

Quote:
Is there a way to get the original exception object from inside a nested or wrapped Exception (for example an EJBException or RemoteException)?
Absolutely yes, but the way to do that depends on the Exception, since there are no standards for that.
Some examples:
·When you have an javax.ejb.EJBException, you can use the getCausedByException() that returns a java.lang.Exception.
·A java.rmi.RemoteException there is a public field called detail of type java.lang.Throwable
·With a java.sql.SQLException you need to use the method getNextException() to get the chained java.sql.SQLException.
·When you have an java.lang.reflect.InvocationtargetException, you can get the thrown target java.lang.Throwable using the getTargetException() method.

Quote:
How can I retrive from inside my Bean (Stateless Session and Entity CMP) the user name which I\'m serving (the user name of user just logged in my web application)?
Inside an EJB you may retrieve the \"Caller\" name, that is the login id by invoking:
sessionContext.getCallerIdentity().getName()
where sessionContext is the instance of \"SessionContext\" (setSessionContext) passed to the Session Bean, or the instance of \"EntityContext\" (setEntityContext) passed to the Entity Bean.

Remaining answers for part 1 later

Post edited by: vasu, at: 2004/09/30 22:21
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new questions
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads

Thread Thread Starter Forum Replies Last Post
How to ace an J2EE Interview!! - PART 1 akpraveen Interview Questions 5 05-07-2007 03:28 AM
comp.lang.c Answers to Frequently Asked Questions (FAQ List) Steve Summit Tech FAQ 0 06-01-2004 06:00 AM
Quarterly ASCII posting of SCO Programmer's FAQ Boyd Lynn Gerber Tech FAQ 0 04-25-2004 10:11 PM
Motif FAQ (Part 4 of 9) Ken Lee Tech FAQ 0 04-18-2004 08:54 AM


All times are GMT -4. The time now is 08:53 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2004 - 2007 Exforsys Inc. All rights reserved.