I am little confused about JPA services and its implementation. In EJB3 in Action , it says JPA standardizes the
ORM framework so that you can run your code with any persistence provider.I am not clear yet that :
1) does JPA not provide implemention for its services i.e EntityManager and cannot be used without persistence provider
i.e (Hibernate or Toplink) ?
2) It also says JPA can be used without container ,so it means if we are using container or app server for example
jboss , then hibernate jars are already included in jboss and we need not to include hibernate jars in classpath ?
3) If we are using JPA without container i.e in a desktop application,then we need to include hibernate jars in classpath
to get the persistence privider or get the implementation of JPA ?
JPA is basically only the standardized specification for O/R mapping in Java. It also defines the necessary interfaces, annotations, XML descriptors etc. you need to use JPA. But it doesn't offer an implementation for JPA. Additionally you need a provider like Hibernate, Toplink or EclipseLink.
If you use a compliant JEE container it must provide some implementation of JPA / JPA 2. The specific implementation may vary from container to container. But at runtime you should have all needed libraries or JARs already in place.
If you use JPA in a standalone application you have to provided the needed JARs for the JPA interfaces and an implementation, i.e. the provider. There are different bundles available which often contain the necessary JARs for JPA interfaces etc. and the JARs for the provider itself. Additionally there are some limitations like container-managed transaction which are obviously not available when using JPA outside a container.
Joined: Aug 21, 2008
Thanks for your reply Marco.
As you mentioned we always need to include required jars in classpath , but I am confused
that I tried a jpa tutorial from laliluna website which is using jboss and I did not include the hibernate jar files in classpath
and the application works fine without those jars ,how come ?
If you create a JEE (= enterprise) application which runs inside an application server (= JBoss) you do NOT need to provided additional JARs. Because JBoss 5.x is EE compliant it already provides some provider for the JPA.
Mark E Hansen
Joined: Apr 01, 2009
Actually, he said when you run your application in a JEE container (like JBoss AS for example), the container is required to provide a JPA implementation, which includes all the necessary Jars, etc. This is what you're seeing.