• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mock exam question (states)

 
Severin Stoeckli
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
33. Which must NOT be invoked on a bean's EJBContext until AFTER
the execution of the setSessionContext
method in a stateless session bean using CMT?

A) getEJBLocalHome
B) getEJBObject
C) getUserTransaction
D) getCallerPrincipal
E) isCallerInRole
F) setRollbackOnly
G) getRollbackOnly
H) getEJBLocalObject

I said:

c, d, e, f, g

The answer was:

c, f, g

why?

Severin
 
Dan T
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
stateless beans dont have a specific user
 
Severin Stoeckli
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
they have, when they're in the business method. And that's definitely AFTER the setSessionContext. It's exactly the same as for the transaction (answer F/G) - or not?

Severin
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have summarized what beans can and cannot do during their lifecycle in my cheat sheet about life cycles and allowed operations of EJBs.

Since the bean uses CMT, answer C is wrong and can be eliminated right away.

On the left of page 4 of my cheat sheet, you can see that stateless CMT session beans can only invoke getEJB(Local)Home() (A) and access the JNDI context java:comp/env during the invocation of setSessionContext(). After setSessionContext() is done executing, ejbCreate() will be called and it will be allowed to call getEJB(Local)Object() (B,H) in addition to what setSessionContext() was allowed to. Finally, business methods may invoke any callback. So strictly speaking, the correct answers to this question should be B and H since just after setSessionContext(), ejbCreate() will be called and it may not invoke D,E,F,G.
 
Dan T
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if u are using HF-EJB, on page 228 it says:

"Unlike stateFUL beans, a stateLESS bean can't get caller security info in ejbCreate, becuase there IS no client assocaited with the stateless bean's creation. It is the Container that decides to create the bean, and not tied to any client"
 
alzamabar
Ranch Hand
Posts: 379
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Valentin Crettaz:
I have summarized what beans can and cannot do during their lifecycle in my cheat sheet about life cycles and allowed operations of EJBs.

Since the bean uses CMT, answer C is wrong and can be eliminated right away.

On the left of page 4 of my cheat sheet, you can see that stateless CMT session beans can only invoke getEJB(Local)Home() (A) and access the JNDI context java:comp/env during the invocation of setSessionContext(). After setSessionContext() is done executing, ejbCreate() will be called and it will be allowed to call getEJB(Local)Object() (B,H) in addition to what setSessionContext() was allowed to. Finally, business methods may invoke any callback. So strictly speaking, the correct answers to this question should be B and H since just after setSessionContext(), ejbCreate() will be called and it may not invoke D,E,F,G.


Sorry Valentin, in this case the right answer should be All but B and H (I know that you knew).

Anyway, thank you for your sheet. This is pure gold for the exam. Do we own anything to you???
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry Valentin, in this case the right answer should be All but B and H (I know that you knew).
Thanks for the reminder Marco... I really needed some rest on Friday, I guess

Do we own anything to you???
I'm doing this for the benefit of the community. I won't spit on a beer, though
 
alzamabar
Ranch Hand
Posts: 379
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Valentin Crettaz:
Sorry Valentin, in this case the right answer should be All but B and H (I know that you knew).
Thanks for the reminder Marco... I really needed some rest on Friday, I guess

Do we own anything to you???
I'm doing this for the benefit of the community. I won't spit on a beer, though


Well, I don't dislike beer as well. If you come around London, would you join my 'certification' party?


 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I don't dislike beer as well.
Beer or whatever beverage that when consumed homeopathically can greatly contribute to relaxing your body and mind after work

If you come around London, would you join my 'certification' party?
I would if I was able to come over.
 
Severin Stoeckli
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ohw boys, didn't you read the Head First?

...
Your brain works best in a nice bath of fluid.
...
Beer, or something stronger, is called for when you pass the exam


(ok Valentin, you already passed....)




To come back to the question, I disagree with you both (Valentin and Marc): According to Valentin's cheat sheet I would mark the following answers:

For a stateless session bean usig CMT

(A) getEJBLocalHome must NOT be invoked on a bean's EJBContext until AFTER the execution of the setSessionContext ==> wrong, it can be invoked in setSessionContext()

(B) getEJBObject must NOT be invoked on a bean's EJBContext until AFTER the execution of the setSessionContext ==> true, it can be invoked in ejbCreate, in a business method and in ejbRemove

(C) getUserTransaction must NOT be invoked on a bean's EJBContext until AFTER the execution of the setSessionContext ==> wrong, this method should never be invoked for CMT

(D) getCallerPrincipal must NOT be invoked on a bean's EJBContext until AFTER the execution of the setSessionContext ==> true, should only be invoked in a business method, that's definitely after setSessionContext

(E) isCallerInRole must NOT be invoked on a bean's EJBContext until AFTER the execution of the setSessionContext ==> true, should only be invoked in a business method, that's definitely after setSessionContext

(F) setRollbackOnly must NOT be invoked on a bean's EJBContext until AFTER the execution of the setSessionContext ==> true, should only be invoked in a business method, that's definitely after setSessionContext

(G) getCallerPrincipal must NOT be invoked on a bean's EJBContext until AFTER the execution of the setSessionContext ==> true, should only be invoked in a business method, that's definitely after setSessionContext

(H) getEJBLocalObject must NOT be invoked on a bean's EJBContext until AFTER the execution of the setSessionContext ==> true, it can be invoked in ejbCreate, in a business method and in ejbRemove

So the solution would be

B,D,E,F,G,H


(or, strictly only B,H then Valentin's answer would be right...)




...well, and if somebody of you come around Z�rich let me know for the



Thanks to all participants for the contribution

Severin
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ohw boys, didn't you read the Head First?
co-edited it

Beer, or something stronger, is called for when you pass the exam
I'm the living example that this is not a tautology

...well, and if somebody of you come around Z�rich let me know for the
We had a small Javaranch gathering in Bern about a month ago, we might organize another one in Zurich (or Schlieren for that matter ) at some point... Stay tuned...

Let's get serious... I think by now we all agree that the question statement would need a serious rework as it is very ambiguous. It is not clear whether "until AFTER
the execution of the setSessionContext" means immediately after setSessionContext() or at any time after setSessionContext()...
[ August 03, 2004: Message edited by: Valentin Crettaz ]
 
alzamabar
Ranch Hand
Posts: 379
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Severin St�ckli:
Ohw boys, didn't you read the Head First?

...
Beer, or something stronger, is called for when you pass the exam[/b]


Unfortunately you're right.



This exam is costing to me more than I expected.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic