In the same way that our Entity Bean is identified as such to the server by an annotation, we will mark Library.java class of our LibraryLocal local interface as @Stateless.


The Session Bean handles our Entity Bean persistence by using the EntityManager, our handle to the server's persistence provider.


We mark our EntityManager with @PersistenceContext annotation so that our EJB3 container will supply its value (via dependency injection) when we use it so we do not need to create or look it up.


To implement all our business methods we use the EntityManager to persist, find (by primary key), remove and query our entity.


EJB3 Java Persistence API (JPA) provides a controlled way to use EJB-QL to retrieve entities - note the very basic query in the getBooks() method.


                    

Copyright © 2012 VisualBuilder. All rights reserved