我正在尝试将Hibernate与Mule集成。 Mule是否支持Hibernate Transport?
嗨@David,
我尝试使用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);
}
}
获取以下异常请告诉我解决方案。
线程中的异常&#34; main&#34; org.mule.module.launcher.DeploymentInitException:IllegalAccessError: 试图访问方法org.hibernate.engine.CascadeStyle。()V 来自类org.hibernate.engine.EJB3CascadeStyle $ 1 at org.mule.module.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) 在 org.mule.tooling.server.application.ApplicationDeployer.main(ApplicationDeployer.java:127) 引起:org.mule.api.config.ConfigurationException:创建错误 bean名称为&#39; entityManagerFactory&#39;在类路径资源中定义 [applicationContext.xml]:调用init方法失败;嵌套 异常是java.lang.IllegalAccessError:试图访问方法 org.hibernate.engine.CascadeStyle。()来自类的V. org.hibernate.engine.EJB3CascadeStyle $ 1 (org.mule.api.lifecycle.InitialisationException) (org.mule.api.config.ConfigurationException)at org.mule.config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:52) 在 org.mule.config.builders.AbstractResourceConfigurationBuilder.configure(AbstractResourceConfigurationBuilder.java:78) 在 org.mule.context.DefaultMuleContextFactory.createMuleContext(DefaultMuleContextFactory.java:84) 在 org.mule.module.launcher.application.DefaultMuleApplication.init(DefaultMuleApplication.java:207) ... 3更多引起:org.mule.api.config.ConfigurationException: 创建名称为&#39; entityManagerFactory&#39;的bean时出错在课堂上定义 path resource [applicationContext.xml]:调用init方法 失败;嵌套异常是java.lang.IllegalAccessError:试过 访问方法org.hibernate.engine.CascadeStyle。()V来自类 org.hibernate.engine.EJB3CascadeStyle $ 1 (org.mule.api.lifecycle.InitialisationException)at org.mule.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.AutoConfigurationBuilder.doConfigure(AutoConfigurationBuilder.java:57) 在 org.mule.config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:46) ... 6更多引起:org.mule.api.lifecycle.InitialisationException: 创建名称为&#39; entityManagerFactory&#39;的bean时出错在课堂上定义 path resource [applicationContext.xml]:调用init方法 失败;嵌套异常是java.lang.IllegalAccessError:试过 访问方法org.hibernate.engine.CascadeStyle。()V来自类 org.hibernate.engine.EJB3CascadeStyle $ 1 at org.mule.registry.AbstractRegistry.initialise(AbstractRegistry.java:117) 在 org.mule.config.spring.SpringXmlConfigurationBuilder.createSpringRegistry(SpringXmlConfigurationBuilder.java:119) 在 org.mule.config.spring.SpringXmlConfigurationBuilder.doConfigure(SpringXmlConfigurationBuilder.java:73) 在 org.mule.config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:46) ... 10更多引起: org.springframework.beans.factory.BeanCreationException:错误 创建名为&entityManagerFactory&#39;的bean在类路径中定义 resource [applicationContext.xml]:init方法的调用失败; 嵌套异常是java.lang.IllegalAccessError:试图访问 方法org.hibernate.engine.CascadeStyle。()来自类的V. org.hibernate.engine.EJB3CascadeStyle $ 1 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1486) 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:524) 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461) 在 org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:295) 在 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) 在 org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292) 在 org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) 在 org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1117) 在 org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:922) 在 org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) 在 org.mule.config.spring.SpringRegistry.doInitialise(SpringRegistry.java:89) 在 org.mule.registry.AbstractRegistry.initialise(AbstractRegistry.java:109) ... 13更多引起:java.lang.IllegalAccessError:试图访问 方法org.hibernate.engine.CascadeStyle。()来自类的V. org.hibernate.engine.EJB3CascadeStyle $ 1 at org.hibernate.engine.EJB3CascadeStyle $ 1(EJB3CascadeStyle.java:24) 在 org.hibernate.engine.EJB3CascadeStyle。(EJB3CascadeStyle.java:19) 在 org.hibernate.ejb.event.EJB3PersistEventListener。(EJB3PersistEventListener.java:19) 在 org.hibernate.ejb.EventListenerConfigurator。(EventListenerConfigurator.java:81) 在 org.hibernate.ejb.Ejb3Configuration。(Ejb3Configuration.java:136) 在 org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:130) 在 org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:225) 在 org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:308) 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1545) 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1483) ......还有24个