0

Trying to implement Mule module JPA with Hibernate in Mule and unable to persist data using . When I check in db, no values are inserted. I referred this link, but am unable to implement the solution given in this link, Mule JPA persist is not inserting or updating.

Could someone please elaborate or provide alternate suggestions on this? Thanks.

<code>
   <spring:beans>
    <spring:import resource="classpath:Spring/applicationContext.xml" />
    </spring:beans>
       <spring:beans>
<spring:bean id="myBean" class="org.Location">
 </spring:bean>
     <spring:bean class="org.springframework.orm.jpa.JpaTransactionManager"
          id="transactionManager">
        <spring:property name="entityManagerFactory" ref="entityManagerFactory"/>
    </spring:bean>
 </spring:beans> 
   <jpa:config name="JPA" entityManagerFactory-ref="entityManagerFactory" doc:name="JPA"/>    
        <flow name="FlowParseJson">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/parseJSON" doc:name="HTTP"/>
        <parse-template location="/jsonjpacheck" doc:name="Parse Template"/>
        <json:json-to-object-transformer returnClass="org.Location" doc:name="JSON to Object"/>
        <logger  message="#[message.payload]" level="INFO" doc:name="In Transaction"/>
    <transactional action="ALWAYS_BEGIN" doc:name="Transactional">
          <jpa:persist  entity-ref="#[payload]" config-ref="JPA" doc:name="Java Persistence API"/> 
    </transactional>
         <logger  message="#[message.payload]" level="INFO" doc:name="After Transaction"/>
        </flow>
</code>

And Persistence.xml

<code>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
        version="2.0">

    <persistence-unit name="default" transaction-type="RESOURCE_LOCAL">
         <provider>org.hibernate.ejb.HibernatePersistence</provider>
          <class>org.Location</class>
        <properties>
            <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
            <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/xxxx" />
            <property name="hibernate.connection.username" value="xxx" />
            <property name="hibernate.connection.password" value="xxxx" />

            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.hbm2ddl.auto" value="create" />
        </properties>
    </persistence-unit>

</persistence>
</code>

And applicationcontext.xml,

<code>
      <context:spring-configured/>
            <context:annotation-config />
        <bean id="entityManagerFactory"
      class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean>
            <property name="persistenceUnitName" value="default" />
            <property name="jpaVendorAdapter">
                <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                 <property name="showSql" value="true"/>
                    <property name="generateDdl" value="true"/>
                </bean>
            </property>
        </bean>
            <bean class="org.springframework.orm.jpa.JpaTransactionManager"
                  id="transactionManager">
                <property name="entityManagerFactory" ref="entityManagerFactory"/>
            </bean>

           <bean id="sessionFactory" factory-bean="entityManagerFactory" factory-method="getSessionFactory"/>

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

    </code>
Community
  • 1
  • 1
malini J
  • 5
  • 7
  • Please [edit] your question and add the code that is relevant to understand what you have tried. –  Aug 20 '15 at 12:18
  • I have edited it. JPA is not persisting and no errors on compilation/runtime. Suggested custom-transaction, but please help on how to implement it? – malini J Aug 21 '15 at 11:16

2 Answers2

3

Here is another alternative example mule_spring_hibernate . After long battles to get get the correct libraries working together I decided I needed to create a demo project and share

Please take note of the loader.override=org.hibernate entry in the mule-deploy.properties file.

  • Hey @Noel Nightingale, thanks for the answer, how does the loader.override work? I added this item, but now my deployments are failing with a null pointer exception for some reason – Nathan Tregillus Jun 06 '16 at 16:29
0

As an alternative, consider persisting data via Hibernate from a Mule component. Working example of this in Mule 3.6.1 may be found here.

Gabriel Dimech
  • 699
  • 5
  • 10