1.Which of the following statements regarding session beans are true? [Check all correct answers]
1. Invoking javax.ejb.EJBObject.getPrimaryKey() on a session bean results in javax.ejb.EJBException been thrown. 2. Invoking javax.ejb.EJBLocalObject.getPrimaryKey() on a session bean results in javax.ejb.EJBException been thrown. 3. Invoking javax.ejb.EJBHome.remove(java.lang.Object primaryKey) on a session bean results in javax.ejb.RemoveException been thrown. 4. Invoking javax.ejb.EJBLocalHome.remove(java.lang.Object primaryKey) on a session bean results in javax.ejb.RemoveException been thrown. 5. Invoking javax.ejb.EJBHome.remove(java.lang.Object primaryKey) on a session bean results in java.rmi.RemoteException been thrown
my answers:2,3,4. given answers:2,5
I have a doubt about the exceptions we get when we call remove on the Home interface. In HFE page:559 it was clearly stated that client gets a Remove exception regardless of client being a remote or local one.
But in some mock exams it was given that client gets Remote Exception
which one is the right answer?
2.Which of the following statements are requirements for a session bean's session bean class? [Check all correct answers]
1. The class must implement the javax.ejb.SessionSynchronization interface. 2. The class must implement the javax.ejb.SessionBean interface. 3. The class may implement the session bean's component interface. 4. The class can be declared final. 5. If the class is a stateful session bean, the constructor must declare parameters to initialise the session state
Myanswer:2 Given answers:2,3
how can 3 be the right choice.can any one explain it?
1. My answer 2,3,4. The answer given may be wrong, but spec confirms your answer.
EJBSpec section 6.6 The EJBObject.getPrimaryKey() method results in a java.rmi.RemoteException and the EJBLocalObject.getPrimaryKey() method results in a javax.ejb.EJBException, and the EJBHome.remove(Object primaryKey) and the EJBLocalHome.remove(Object primaryKey)methods result in a javax.ejb.RemoveException if called on a session bean. If the EJBMetaData.getPrimaryKeyClass() method is invoked on a EJBMetaData object for a session bean, the method throws the java.lang.RuntimeException.
2. According to HFEJB, a session bean developer may choose to implement the Componenet interface and there is nothing either in the Server implementatio or in the Spec that stops you from doing it, though it is generally considered a bad design where you are giving the access to your bean to the client directly instead of through its bodygaurd "the componenet interface impl object".
PS. Remember Mock exam questions does not mention how many answers you need to choose, this makes it tough to decide, but the real exam gives you how many to chose.
The EJB 2.1 spec (sections 6.3.2 and 6.4.2) is clear. 6.3.2 says: "Because session objects do not have primary keys that are accessible to clients, invoking the javax.ejb,EJBHome.remove(Object primaryKey) method on a session results in a javax.ejb.RemoveException."
There is nothing wrong with over-implementing a SessionBean class. Implementing the component interface is one way of achieving a compile-time consistency check on the business methods defined in the SessionBean and the component interface. Unfortunately, it's cumbersome because the SessionBean must then also provide placeholder implementations for the other methods in the component interface. An alternative and perhaps slightly less cumbersome approach would be to factor out only the relevant methods, and place them in a third interface which is then referenced by both the SessionBean and the component interface.
Hi, Yeah yo may be right that it is vendor dependent which oneis thrown, but for the sake of exam should we go with the Spec or the Vendor details, I thought that according to spec it must throw RemoveException now how to deal with what vendor decides to throw it will become a problem, because then your code is tied in, if vendor throws more generalised its fine , if more specificthen the client needs to catch it .
Hope i am clear. Please somebody clarify which one should we go with Spec or Vendor details.