尝试在Mule中使用Hibernate实现Mule模块JPA,并且无法使用持久化数据。当我签入db时,没有插入任何值。我引用了此链接,但无法实现此链接中提供的解决方案Mule JPA persist is not inserting or updating。
有人可以详细说明或提供替代建议吗?感谢。
<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>
和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>
和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>
答案 0 :(得分:3)
这是另一个替代示例mule_spring_hibernate。经过长时间的斗争才能让正确的库一起工作,我决定创建一个演示项目并分享
请注意mule-deploy.properties文件中的loader.override = org.hibernate条目。
答案 1 :(得分:0)
作为替代方案,请考虑persisting data via Hibernate from a Mule component。可以在Mule 3.6.1中找到这个工作示例here。