How do you inject a JPA EntityManager(Factory) using JSF on Tomcat?
Is it possible to configure JPA to inject EntityManager or
EntityManagerFactory on Tomcat?
I'm reading
<http://openjpa.apache.org/docs/latest/manual/>
and
<http://java.sun.com/javaee/5/docs/tutorial/doc/bnbrm.html#bnbrp>
I'm not using Spring or like framework. I have Sun's JSF libs, along with
MyFaces and Tomahawk, plus Apache OpenJPA installed in the project.
I aim to use persistence annotations to declare a class's EntityManagerFactory
member, like this:
public class Foo
{
@PersistenceUnit( unitName="myPersist" )
private EntityManagerFactory emf;
....
}
or likewise for an EntityManager member:
public class Fiz
{
@PersistenceContext( unitName="myPersist" )
private EntityManager em;
....
}
NetBeans thinks it knows all about JPA, so it already helpfully created a data
source definition for my database (e.g., "jdbc/myDs") and a persistence.xml to
map it (e.g., to "myPersist").
My questions are:
- Is there a way to achieve this resource injection given a JSP / JSF
framework on Tomcat, without adding Spring or the like?
- Is Spring a solution to this? Are there others like it?
- Generally how would one configure a web application to use JPA by resource
injection?
I'm working lately on getting this to work within Glassfish, which explicitly
claims to support injecting JPA this way.
--
Lew