3 Replies Latest reply on Feb 23, 2014 12:52 PM by objectiser

    Hibernate JPA example

    objectiser

      Hi

       

      Is there an example of using JPA with Hibernate on JBoss Fuse (specifically on 6.1)?

       

      I had a look on the Fuse By Example page, which lists the 'esb-transactions' example as using JPA and Hibernate, however it is openjpa not hibernate. However I thought I would try this example anyway, and got:

       

      JBossFuse:karaf@root> features:install transactions-openjpa-demo

      Refreshing bundles org.springframework.context.support (117), org.springframework.core (114), org.springframework.context (116)

      Error executing command: Could not start bundle mvn:org.apache.geronimo.components/geronimo-connector/2.2.2 in feature(s) transactions-openjpa-demo-0.0.0: Unresolved constraint in bundle org.apache.geronimo.components.geronimo-connector [248]: Unable to resolve 248.0: missing requirement [248.0] osgi.wiring.package; (&(osgi.wiring.package=org.apache.geronimo.transaction.manager)(version>=2.2.0)(!(version>=3.0.0)))

      JBossFuse:karaf@root>

       

      Thanks in advance.

       

      Regards

      Gary

        • 1. Re: Hibernate JPA example
          chubutin

          I don't have an example, but  I can show you how I configure Hibernate with Mysql or SQL in many projects I have.

           

          Install the features:

           

          <feature>jpa</feature>

          <feature>jpa-hibernate</feature>

           

          Install the drivers

           

          osgi:install mvn:mysql/mysql-connector-java/5.1.18

          osgi:install wrap:mvn:com.microsoft.sqlserver/sqljdbc4/4.0

           

          Import the drivers into your bundle

           

          <plugin>

            <groupId>org.apache.felix</groupId>

            <artifactId>maven-bundle-plugin</artifactId>

            <version>2.3.7</version>

            <extensions>true</extensions>

            <configuration>

            <instructions>

            <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>

            <Import-Package>

            com.mysql.jdbc;resolution:=optional,

            com.microsoft.sqlserver.jdbc;resolution:=optional,

            org.hibernate;resolution:=optional,

            org.hibernate.annotations;resolution:=optional,

            org.hibernate.criterion;resolution:=optional,

            javassist.util.proxy;resolution:=optional,

            org.hibernate.proxy;resolution:=optional,

            org.hibernate.dialect;resolution:=optional,

            org.springframework.aop;resolution:=optional,

            org.springframework.aop.framework;resolution:=optional,

            org.aopalliance.aop;resolution:=optional,

            javax.persistence.criteria;resolution:=optional,

            javax.persistence.metamodel;resolution:=optional,

            *;resolution:=optional,

            </Import-Package>

            <Bundle-Description>${project.description}</Bundle-Description>

            <Export-Package>

            </Export-Package>

            </instructions>

            </configuration>

            </plugin>

           

           

          And you can use Hibernate inside you service!

           

          <!-- CONFIGURACION HIBERNATE JPA -->

           

            <bean id="transactionManager"

            class="org.springframework.orm.hibernate3.HibernateTransactionManager">

            <property name="sessionFactory" ref="sessionFactory" />

            </bean>

           

           

            <!-- enable the configuration of transactional behavior based on annotations -->

            <!-- <tx:annotation-driven transaction-manager="transactionManager" /> -->

           

           

            <bean id="sessionFactory"

            class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">

            <property name="dataSource" ref="dataSource" />

            <property name="packagesToScan">

            <list>

            <value>com.esb.entities</value>

            </list>

            </property>

            <property name="hibernateProperties">

            <props>

            <prop key="hibernate.dialect">${hibernateDialect}</prop>

            <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>

            <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>

            <prop key="cache.provider_class">{cache.provider_class}</prop>

            <prop key="cache.use_query_cache">${cache.use_query_cache}</prop>

            <prop key="cache.use_minimal_puts">${cache.use_minimal_puts}</prop>

            <prop key="max_fetch_depth">${max_fetch_depth}</prop>

            <!-- Print SQL to stdout. -->

            <prop key="show_sql">${show_sql}</prop>

            <prop key="format_sql">${format_sql}</prop>

            </props>

            </property>

            </bean>

           

            <!-- TEST DATASOURCE -->

           

            <bean id="dataSource" class="com.microsoft.sqlserver.jdbc.SQLServerDataSource">

            <property name="URL" value="${urlDataSource}" />

            <property name="user" value="${databaseUser}" />

            <property name="password" value="${databasePassword}" />

            </bean>

          • 2. Re: Hibernate JPA example
            davsclaus

            A community users created this github project with a JPA Hibernate example on JBoss Fuse 6.1

            pires/fabric8-persistence-hibernate · GitHub

            • 3. Re: Hibernate JPA example
              objectiser

              Thanks I'll check it out.