• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

About EPractice Lab mock 2 question 14

 
Himai Minh
Ranch Hand
Posts: 1361
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In EPractice labs mock 2, question 14:
A EJB developer writes two session beans for implementing shopping store. The first session bean, ShoppingCart, collects orders and is implemented as a stateful session bean. The second session bean , CalculatorDiscount is implemented as a stateless session bean and runs on a different server. ShoppingCart contains the method getTotalPrice, which calculates the total price of the order in the ShoppingCart, including discounts. Discounts are calculated by CalculateDiscount using the information on the ShoppingCart bean, combined with data from a database.
Which design can accomplish this?

....
b. The CalculatedDiscount offers a method calculate which is invoked by the ShoppingCart bean. CalculateDiscount accesses the ShoppingCart instance by JNDI lookup.
c. The CalculatedDiscount offers a method calculate which is invoked by the ShoppingCart bean passing its reference obtained from the SessionContext.getBusinessObject method.
.....


b works : SessionContext.getBusinessObject() won't cause illegalLoopBack exception as ShoppingCart and CalculatedDiscount are on different server, as I believe.
The answer is c. But I think b is can also be the answer as CalculateDiscount should do an JNDI look up to inject a ShoppingCart bean.
 
Himai Minh
Ranch Hand
Posts: 1361
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me answer my own question.
For option c, it means getting a reference like this :

The CalculateDiscount can pass the cart reference like this: calculate (cart);

For option b, if we do a JNDI lookup for ShoppingCart, it will return a new instance of this stateful bean. If we use getBusinessObject, we will get the same instance of the stateful bean.
The question itself is asking for getting the same instance of the bean, not a new one.
CaculateDiscount using the information on the ShoppingCart bean.
(that ShoppingCart bean is refering to the same bean instance in the application, not a new one.)

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic