• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Remove vs Remote

 
srinija kosaraju
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

thanks in advance
srinija

SCJP 1.4,SCWCD 1.4
 
Nileesha Bojjawar
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

hope this helps.
 
Ron Olson
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Ron
 
srinija kosaraju
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mr.Nileesha and Mr.Ron

I am going to write SCBCD exam this Friday.Thanks for ur help.Know i am clear about Home remove calls and EJBObject.getPrimarykey calls and Session beans component contract

thank you very much
srinija

SCJP1.4,SCWCD 1.4
[ October 12, 2004: Message edited by: srinija kosaraju ]
 
Nileesha Bojjawar
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Srinija,

Good luck with your exam .
By the Way, I am Ms. Nileesha

tip: dont address anybody withthier title, that's the safest bet..
 
VP Jain
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

If i am not mistaken in HFE book, it states that

the vendor may throw a more generalised exeception or a more specific exception

and it quoted a scenario between CreateException and DuplicateKeyException.

Going by that stand, i think

the correct answers are : 2,5.
 
Nileesha Bojjawar
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic