In this tutorial: http://www.objectdb.com/tutorial/jpa/eclipse/ee/servlet
Is @EJB GuestDao guestDao; merely a way of loading the model on the page so it can be used? If I wasn’t in a servlet and didn’t have access to @EJB how would I load the model? Can I load models from other models?
With that you are defining your servlet’s (could be another ejb) dependecy on the ejb
GuestDao. When the servlet is instantiated by the container, it makes sure that it injects the ejb (servlet’s dependency) into the servlet.It works on local ejbs, whereas if it were a remote ejb then you would have to do a JNDI lookup.
Check out the API Doc.
Alternative to that would be to use something called
EntityManager. Which can be injected into the servlet by by using the annotation@PersistenceContextif you are using container managed persistence. But you can also create it programmatically (when you are not in a servlet and don’t have access to@EJB) by usingEntityManagerFactory.See example of how you would do that in a desktop application here.