Saturday, December 22, 2012

EJB Excercise - 1

What exception is thrown for EJB client when you attempt to invoke a method on an object that no longer exists?
Choice 1
    NoSuchEJBException
Choice 2
    FinderException
Choice 3
    EJBException
Choice 4
    ObjectNotFoundException   // answer
Choice 5
    AccessLocalException


During the lifecycle of a Message-driven bean, the container invokes which lifecycle callbacks?
Choice 1

    PrePassivate and PreDestroy
Choice 2
    PostConstruct and PreDestroy
Choice 3
    PostConstruct and PostActivate
Choice 4
    PrePassivate and PostActivate
Choice 5
    PrePassivate and PostConstruct



Which annotation do you use to specify the security roles permitted to access your application, EJB module, EJB, or business methods?
Choice 1
    @DeclareRoles
Choice 2
    @PermitRoles
Choice 3
    @MethodPermissions
Choice 4
    @RolesPermissions
Choice 5
    @RolesAllowed // answer


You have an enterprise application that needs to display a large list of categories in order to let a user select from that list. The average size of the list is 100.
Question     Based on the scenario above, which enterprise bean incurs the least amount of resource overhead?

Choice 1
    Message driven bean
Choice 2
    Stateless session bean
Choice 3
    Standard Java bean
Choice 4
    Entity bean // answer
Choice 5
    Stateful session bean


You implement javax.ejb.SessionSynchronization in:
Choice 1
    stateless session beans with bean-managed transactions.
Choice 2
    message driven beans.
Choice 3
    stateful session beans with container-managed transactions.
Choice 4
    stateless session beans with container-managed transactions.
Choice 5
    entities.


Which method is first called by the EJB container on a stateless session bean?
Choice 1
    postConstruct()
Choice 2
    setSessionContext()
Choice 3
    newInstance()
Choice 4
    initialize()
Choice 5
    create()  // answer



What can you inject by defining the dependency injection through the annotation @Resource?

Choice 1
    Entity beans
Choice 2
    Session beans
Choice 3
    PersistenceContext
Choice 4
    EJB Reference
Choice 5
    DataSource // answer

To facilitate test driven development, the EJB 3.0 specification allows you to use annotations to inject dependencies through annotations on fields or setter methods. Instead of complicated XML ejb-refs or resource refs, you can use the @EJB and @Resource annotations to set the value of a field or to call a setter method within your session bean with anything registered within JNDI. You can use the @EJB annotation to inject EJB references and @Resource to access datasources.

1 comment: