4 Replies Latest reply on Jan 21, 2008 4:34 PM by nickarls

    using JPA vs. Hibernate with SEAM apps

    asookazian

      according to EJB3 in Action by Debu et al, "JPA is now the standard API to build the persistence tier for applications." - pg. 533

      What are the advantages/disadvantages of using Hibernate (e.g. Session interface) vs. JPA (e.g. EntityManager interface) knowing that JPA is a sub-set of Hibernate API? I'm assuming you get more functionality with Hibernate API.

      http://www.hibernate.org/hib_docs/v3/api/org/hibernate/Session.html
      http://java.sun.com/javaee/5/docs/api/javax/persistence/EntityManager.html

      We are currently using JPA with Hibernate as the persistence provider (vs. Toplink). This is different from using Hibernate API's exclusively with no EntityManager references, etc.

      persistence.xml snippet:

       <persistence-unit name="boIcomsSecurityAudit">
       <provider>org.hibernate.ejb.HibernatePersistence</provider>
       <jta-data-source>java:/boIcomsSecurityAuditDatasource</jta-data-source>
       <properties>
       <property name="jboss.entity.manager.factory.jndi.name" value="java:/securityAuditBoIcomsEntityManagerFactory"/>
       </properties>
       </persistence-unit>


      What is the official JBoss Seam recommendation for Seam apps? Should we use Hibernate API directly or JPA? I have a feeling it's one of the "it depends" answers. Most of the examples I've seen in the Seam books use the EntityManager interface for JPA. thx.

        • 1. Re: using JPA vs. Hibernate with SEAM apps
          nickarls

          Personally I use the "standards first"-approach. You can probably cover 90+% of your needs with JPA and for the rest you can easily fall back on Hibernate-extended annotations or the Hibernate session.

          • 2. Re: using JPA vs. Hibernate with SEAM apps

            Even when using JPA, it is still possible to reach down to get Hibernate if you need something from it. (assuming Hibernate is your persistence provider, that is) I think I'd always start with the JPA interfaces.

            • 3. Re: using JPA vs. Hibernate with SEAM apps
              asookazian

               

              "norman.richards@jboss.com" wrote:
              Even when using JPA, it is still possible to reach down to get Hibernate if you need something from it. (assuming Hibernate is your persistence provider, that is) I think I'd always start with the JPA interfaces.


              what do you mean by "reach down to get Hibernate" exactly? Are you talking about using the javax.persistence.Session interface directly as required in a class and importing the appropriate package/interface?

              so in other words, use JPA (e.g. EntityManager) most of the time unless you need a method that JPA api does not provide but Hibernate API does?

              • 4. Re: using JPA vs. Hibernate with SEAM apps
                nickarls

                the EntityManager has a getDelegate() method that returns an Object that can be cast to the underlying providers (e.g. Hibernate) Session or similar