• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Answer to this question and why ?

 
Will Hunt
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From which method in a stateless session bean can the begin method be called?


A. the setSessionContext method in a CMT demarcated bean
B. the ejbRemove method in a BMT demarcated bean
C. a business method in a CMT demarcated bean
D. a business method in a BMT demarcated bean
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suspect that the being method being called is the one declared in the javax.transaction.UserTransaction interface. If this is the case, then A and C can be eliminated because CMT beans cannot use the UserTransaction interface. Then since we are talking about stateless session beans, only answer D makes sense as BMT session beans can only use the UserTransaction interface in their business methods and not in their ejbRemove method. (Table 3, page 90 of the spec)

Note: if we were talking about stateful session beans, the story would be different as answers B and D would be both correct (Table 2, page 80 of the spec)
 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to digress a bit.

The spec says that stateless sbean ejbCreate/ejbRemove() can look up the UserTransaction but not to call methods on it.

But, what is the rationale behind the difference? It seems that this is the only place where the rule for look up UserTransaction is 'decoupled' from calling UserTransaction methods.
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the question statement explicitely states that the begin method will be called, so this has nothing to do with the lookup itself...
 
Lionel Orellana
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems that this is the only place where the rule for look up UserTransaction is 'decoupled' from calling UserTransaction methods.

The same happens in ebjCreate/Remove of MDB. I find this annoying too, I don't understand why you are able to look it up if you can't use it. Does anyone know what the story is here? I have the feeling it's one of those the-spec-says-so things ...
 
Will Hunt
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is one of the questions in the sun practice exams. It says answer is D, which makes sense. Even though you have the sessionContext reference, only you can call non-transaction related methods. Since they all throw IllegalStateException when called in a non tx method and all the SessionBean interface run in unspecified Tx, it can only be business method in BMT.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic