Question: Why would a client application use JTA transactions? (JTA)
Answer: One possible example would be a scenario in which a client needs to employ two (or more) session beans, where each session bean is deployed on a different EJB server and each bean performs operations against external resources (for example, a database) and/or is managing one or more entity beans. In this scenario, the client's logic could required an all-or-nothing guarantee for the operations performed by the session beans; hence, the session bean usage could be bundled together with a JTA UserTransaction object.
In the previous scenario, however, the client application developer should address the question of whether or not it would be better to encapsulate these operations in yet another session bean, and allow the session bean to handle the transactions via the EJB container. In general, lightweight clients are easier to maintain than heavyweight clients. Also, EJB environments are ideally suited for transaction management.
... Context c = new InitialContext(); UserTransaction ut = (UserTransaction)
c.lookup("java:comp/UserTransaction"); ut.begin(); // perform multiple operations... ut.commit() ...
Question: Can the bean class implement the EJBObject class directly? If not why?
Answer: It is better not to do it will make the Bean class a remote object and its methods can be accessed without the containers? security, and transaction implementations if our code by mistake passed it in one of its parameters. Its just a good design practice.
Question: What does isIdentical() method return in case of different type of beans?
Answer: Stateless ? true always
Stateful ? depends whether the references point to the same session object
Entity ? Depends whether the primary key is the same and the home is same
Question: How should you type cast a remote object? Why?
Answer: A client program that is intended to be interoperable with all compliant EJB Container implementations must use the javax.rmi.PortableRemoteObject.narrow(...) method to perform type-narrowing of the client-side representations of the remote home and remote interfaces. Programs using the cast operator for narrowing the remote and remote home interfaces are likely to fail if the Container implementation uses RMI-IIOP as the underlying communication transport.
Question: What should you do in a passivate method?
Answer: You try to make all nontransient variables, which are not one of the following to null. For the given list the container takes care of serializing and restoring the object when activated.
Serializable objects, null, UserTransaction, SessionContext, JNDI contexts in the beans context, reference to other beans, references to connection pools.
Things that must be handled explicitly are like a open database connection etc. These must be closed and set to null and retrieved back in the activate method.
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment