0

我正在尝试将 Hibernate 与 Mule 集成。Mule 是否支持休眠传输?

嗨@大卫,

我曾尝试使用 Mule JPA 模块。但我面临以下问题。请帮助我。

这是我的 applicationContect.xml

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop"
        xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee"
        xmlns:tx="http://www.springframework.org/schema/tx"
        xsi:schemaLocation="
            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
            http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

    <context:property-placeholder location="classpath:jdbc.properties"/>

    <!-- Connection Pool -->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
        <property name="driverClass" value="${jdbc.driverClass}"/>
        <property name="jdbcUrl" value="${jdbc.url}"/>
        <property name="user" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
    </bean>

    <!-- JPA EntityManagerFactory --> 
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
            p:dataSource-ref="dataSource">
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                    <property name="database" value="${jdbc.database}"/>
                    <property name="showSql" value="${jdbc.showSql}"/>      
            </bean>     
        </property>
    </bean>

    <!-- Transaction manager for a single JPA EntityManagerFactory (alternative to JTA) -->
    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
            p:entityManagerFactory-ref="entityManagerFactory"/>

    <!-- Activates various annotations to be detected in bean classes for eg @Autowired-->
    <context:annotation-config/>

      <!-- enable the configuration of transactional behavior based on annotations  -->
      <tx:annotation-driven transaction-manager="transactionManager"/>

    <!-- Property Configurator -->
    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location" value="jdbc.properties"/>
    </bean>



    <context:component-scan base-package="com.test.dao"/>

    <bean id="contactService" class="com.test.service.ContactServiceImpl"/>

</beans>

这是我的 mflow 文件

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.4.1"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:jpa="http://www.mulesoft.org/schema/mule/jpa"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/jpa http://www.mulesoft.org/schema/mule/jpa/current/mule-jpa.xsd">

  <spring:beans>
           <spring:import resource="classpath:applicationContext.xml" />
    </spring:beans>


        <jpa:config name="Java_Persistence_API" entityManagerFactory-ref="entityManagerFactory" doc:name="Java Persistence API"/>
    <flow name="jpa-exampleFlow1" doc:name="jpa-exampleFlow1">
        <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/>

   <!-- code to be written -->
        <logger level="INFO" doc:name="Logger"/>
    </flow>
</mule>

这是我的实体类

package com.test.entities;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Table;
import javax.persistence.Transient;

import javax.persistence.*;
import com.test.vo.Contact;
import com.test.vo.ContactVO;

@Entity
@Table(name="contact")

public class ContactEO implements Contact{

    @Transient
    Contact contact;

    @Transient
    public Contact getContact() {
        return contact;
    }

    public void setContact(Contact contact) {
        this.contact = contact;
    }

    public ContactEO(){
        contact = new ContactVO();
    }

    public ContactEO(Contact contact){
        this.contact = contact;
    }

    @Column(name="FIRSTNAME")
    public String getFirstName() {
        return contact.getFirstName();
    }

    public void setFirstName(String firstName) {
        contact.setFirstName(firstName);
    }

    @Column(name="LASTNAME")
    public String getLastName() {
        return contact.getLastName();
    }

    public void setLastName(String lastName) {
        contact.setLastName(lastName);
    }

    @Column(name="EMAIL")
    public String getEmail() {
        return contact.getEmail();
    }
    public void setEmail(String email) {
        contact.setEmail(email);
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name="ID")
    public long getId() {
        return contact.getId();
    }

    public void setId(long id) {
        contact.setId(id);
    }



}

低于异常请让我知道解决方案。

线程“主”org.mule.module.launcher.DeploymentInitException 中的异常:IllegalAccessError:试图从 org.mule.module 的类 org.hibernate.engine.EJB3CascadeStyle$1 访问方法 org.hibernate.engine.CascadeStyle.()V。 launcher.application.DefaultMuleApplication.init(DefaultMuleApplication.java:219) 在 org.mule.module.launcher.application.ApplicationWrapper.init(ApplicationWrapper.java:64) 在 org.mule.module.launcher.DefaultMuleDeployer.deploy(DefaultMuleDeployer. java:47) at org.mule.tooling.server.application.ApplicationDeployer.main(ApplicationDeployer.java:127) 原因:org.mule.api.config.ConfigurationException:创建类路径中定义的名称为“entityManagerFactory”的bean时出错资源 [applicationContext.xml]:init 方法调用失败;嵌套异常是java。在类路径资源 [applicationContext.xml] 中定义:调用 init 方法失败;嵌套异常是 java.lang.IllegalAccessError: 试图从 org.mule 的类 org.hibernate.engine.EJB3CascadeStyle$1 (org.mule.api.lifecycle.InitialisationException) 访问方法 org.hibernate.engine.CascadeStyle.()V。 config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:52) 在 org.mule.config.builders.AbstractResourceConfigurationBuilder.configure(AbstractResourceConfigurationBuilder.java:78) 在 org.mule.config.builders.AutoConfigurationBuilder.autoConfigure(AutoConfigurationBuilder.java: 101) 在 org.mule.config.builders.AbstractConfigurationBuilder 的 org.mule.config.builders.AutoConfigurationBuilder.doConfigure(AutoConfigurationBuilder.java:57)。configure(AbstractConfigurationBuilder.java:46) ... 6 更多原因:org.mule.api.lifecycle.InitialisationException:在类路径资源 [applicationContext.xml] 中定义名称为“entityManagerFactory”的 bean 创建错误:调用 init 方法失败; 嵌套异常是 java.lang.IllegalAccessError: 试图从 org.mule.registry.AbstractRegistry.initialise(AbstractRegistry.java:117) 类 org.hibernate.engine.EJB3CascadeStyle$1 访问方法 org.hibernate.engine.CascadeStyle.()V ) 在 org.mule.config.spring.SpringXmlConfigurationBuilder.doConfigure(SpringXmlConfigurationBuilder.java:73) 在 org.mule.config.builders.createSpringRegistry(SpringXmlConfigurationBuilder.java:119) 在 org.mule.config.builders.AbstractConfigurationBuilder。configure(AbstractConfigurationBuilder.java:46) ... 10 更多原因:org.springframework.beans.factory.BeanCreationException:在类路径资源 [applicationContext.xml] 中定义名称为“entityManagerFactory”的 bean 创建错误:调用 init 方法失败; 嵌套异常是 java.lang.IllegalAccessError: 试图从 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory 类 org.hibernate.engine.EJB3CascadeStyle$1 访问方法 org.hibernate.engine.CascadeStyle.()V .java:1486) 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory 的 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:524)。

4

1 回答 1

0

JPA 连接器怎么样:http: //www.mulesoft.org/connectors/jpa-connector

于 2014-05-15T01:09:02.427 回答