gpt4 book ai didi

java - 配置 Mule JPA 模块以使用 Eclipse Link 和 MySQL

转载 作者:行者123 更新时间:2023-11-29 03:37:57 24 4
gpt4 key购买 nike

我正在尝试编写一个 Mule ESB 应用程序,该应用程序将 XML 文件读入域对象,然后使用 JPA 将该对象写入 MySQL 数据库。

我已经找出大部分需要的配置,但我遇到了一个问题,Mule JPA 模块 (https://github.com/mulesoft/mule-module-jpa) 似乎没有提交 sql 查询。我已将 Mule JPA 组件设置为刷新查询,我可以看到它们被写入 MySQL 通用日志,但 COMMIT 从未完成,因此数据从未存储过。似乎从未调用模块中 JPATransaction 类的 doCommit() 方法,我看不到它的任何日志输出。但是,事务似乎是使用同一类的 bindResource 方法绑定(bind)的。这可以在日志中看到。

知道我在这里做错了什么吗?

骡子流:

<spring:beans>
<spring:bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSource">
<spring:property name="driverClassName" value="com.mysql.jdbc.Driver" />
<spring:property name="url" value="jdbc:mysql://localhost:3306/interoperability_layer?user=root&amp;password=***" />
<spring:property name="defaultAutoCommit" value="true" />
</spring:bean>

<spring:bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManager">
<spring:property name="entityManagerFactory" ref="entityManagerFactory"/>
</spring:bean>

<spring:bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect" />

<spring:bean id="eclipseLinkVendor" class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
<spring:property name="databasePlatform" value="org.eclipse.persistence.platform.database.MySQLPlatform"/>
<spring:property name="generateDdl" value="false"/>
<spring:property name="showSql" value="false"/>
</spring:bean>

<spring:bean id="entityManagerFactory" name="Bean" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<spring:property name="dataSource" ref="dataSource" />
<spring:property name="persistenceUnitName" value="org.jembi.openhim.jpa" />
<spring:property name="jpaDialect" ref="jpaDialect" />
<spring:property name="jpaVendorAdapter" ref="eclipseLinkVendor" />
<spring:property name="packagesToScan" value="domain"/>
</spring:bean>
</spring:beans>
<jpa:config name="Java_Persistence_API" entityManagerFactory-ref="entityManagerFactory" doc:name="Java Persistence API"/>
<flow name="openhim-report-adapterFlow1" doc:name="openhim-report-adapterFlow1">
<vm:inbound-endpoint exchange-pattern="request-response" path="processReport" doc:name="VM">
</vm:inbound-endpoint>
<component class="org.jembi.openhim.IndicatorReportXmlToObjectTransformer" doc:name="Store indicator reports"/>
<logger message="Converted XML to Report object" level="INFO" doc:name="Logger"/>
<transactional action="ALWAYS_BEGIN" doc:name="Transactional">
<jpa:persist config-ref="Java_Persistence_API" entity-ref="#[payload:]" doc:name="Java Persistence API" flush="true"/>
</transactional>
<logger message="Saved Report object using JPA" level="INFO" doc:name="Logger"/>
<scripting:component doc:name="Groovy">
<scripting:script engine="Groovy"><![CDATA[message.payload = "";]]></scripting:script>
</scripting:component>
<http:response-builder status="201" doc:name="HTTP Response Builder" contentType="application/xml"/>
<logger message="Sending HTTP responce" level="INFO" doc:name="Logger"/>
</flow>

日志输出:

INFO  2013-09-02 16:17:21,601 [[openhim-report-adapter].connector.http.mule.default.receiver.02] org.mule.api.processor.LoggerMessageProcessor: Converted XML to Report object
DEBUG 2013-09-02 16:17:21,633 [[openhim-report-adapter].connector.http.mule.default.receiver.02] org.mule.module.jpa.adapters.JPAModuleProcessAdapter: Persisting: org.jembi.openhim.Report@1749c7ac
DEBUG 2013-09-02 16:17:21,634 [[openhim-report-adapter].connector.http.mule.default.receiver.02] org.mule.module.jpa.adapters.JPAModuleProcessAdapter: Executing JPA command with message: org.jembi.openhim.Report@1749c7ac, command: org.mule.module.jpa.command.Persist@6bf22341 and parameters: null
[EL Info]: 2013-09-02 16:17:21.663--ServerSession(1208128432)--EclipseLink, version: Eclipse Persistence Services - 2.5.0.v20130507-3faac2b
[EL Info]: connection: 2013-09-02 16:17:21.964--ServerSession(1208128432)--file:/home/ryan/MuleStudio/workspace/.mule/apps/openhim-report-adapter/classes_org.jembi.openhim.jpa login successful
DEBUG 2013-09-02 16:17:22,030 [[openhim-report-adapter].connector.http.mule.default.receiver.02] org.mule.module.jpa.JPATransaction: Binding JPA transaction: 621071ed-13da-11e3-a4cd-0907619c09d6
DEBUG 2013-09-02 16:17:22,043 [[openhim-report-adapter].connector.http.mule.default.receiver.02] org.mule.module.jpa.JPATransaction: Binding org.eclipse.persistence.internal.jpa.EntityManagerImpl@2eabef26 to org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean@19e1bfba
DEBUG 2013-09-02 16:17:22,044 [[openhim-report-adapter].connector.http.mule.default.receiver.02] org.mule.module.jpa.command.Persist: Persisting entity: org.jembi.openhim.Report@1749c7ac
INFO 2013-09-02 16:17:22,134 [[openhim-report-adapter].connector.http.mule.default.receiver.02] org.mule.api.processor.LoggerMessageProcessor: Saved Report object using JPA
INFO 2013-09-02 16:17:22,286 [[openhim-report-adapter].connector.http.mule.default.receiver.02] org.mule.api.processor.LoggerMessageProcessor: Sending HTTP responce
DEBUG 2013-09-02 16:17:22,289 [[openhim-report-adapter].connector.http.mule.default.receiver.02] com.mulesoft.mule.config.pool.MonitoredThreadPoolExecutor: Stats{totalTime=979.67, startTime=25637681310485, endTime=25638660979198}
DEBUG 2013-09-02 16:17:22,289 [[openhim-report-adapter].connector.http.mule.default.receiver.02] com.mulesoft.mule.config.pool.MonitoredThreadPoolExecutor: Finished Work: org.mule.execution.FlowProcessingPhase$1@7a670f8b. in Thread[[openhim-report-adapter].connector.http.mule.default.receiver.02,5,main]. Active tasks: 1 (2 threads in a pool)
DEBUG 2013-09-02 16:17:22,290 [[openhim-report-adapter].http.request.dispatch.8085.01] com.mulesoft.mule.config.pool.MonitoredThreadPoolExecutor: Stats{totalTime=1007.19, startTime=25637654077832, endTime=25638661269425}
DEBUG 2013-09-02 16:17:22,290 [[openhim-report-adapter].http.request.dispatch.8085.01] com.mulesoft.mule.config.pool.MonitoredThreadPoolExecutor: Finished org.mule.transport.http.HttpRequestDispatcherWork@b6edc37. in Thread[[openhim-report-adapter].http.request.dispatch.8085.01,5,main]. Active tasks: 0 (1 threads in a pool)

更新

这是我的 persistence.xml 文件:

<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="org.jembi.openhim.jpa" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>

<class>org.jembi.openhim.Report</class>
<class>org.jembi.openhim.Indicator</class>
<class>org.jembi.openhim.DataElements</class>

<properties>
<property name="eclipselink.weaving" value="false"/>
</properties>
</persistence-unit>
</persistence>

最佳答案

其他人报告了一个similar issue使用 mule-module-jpa,模块不会被维护。另外,是否需要使用 eclipselink?看看工作 Mule-JPA example ,这改用 Hibernate。可以找到示例的描述 here .

HTH

关于java - 配置 Mule JPA 模块以使用 Eclipse Link 和 MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18575724/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com