Could anyone point me to a working example of the mule-module-jpa suitable for Mule 3.4 CE?
I have looked high and low and spent the better part of a day trying to get a test running and am stuck trying to get a properly defined entityManagerFactory set inside a mule app.
I got excited when I saw the article here describing the modules features. http://blogs.mulesoft.org/getting-started-with-jpa-and-mule/ Unfortunately that article lacks any details about configuration of the module.
I next found the github repo for the module (https://github.com/mulesoft/mule-module-jpa) and followed the link to the "documentation" at https://github.com/mulesoft/mule-module-jpa. Again no details on the entityManager config. Also noticed that the maven info there seems to be out of date with what Studio will put in maven-mule-plugin for the 1.2.0 version of the mule-module-jpa that Studio will install via the mule update site.
I next looked at the test in the source for the mule-module-jpa at https://github.com/mulesoft/mule-module-jpa/tree/master/src/test/resources to see if I could cobble a solution.
Using that I have gotten Studio and/or maven to compile a small mule app using the module but it wont start giving a Caused by: java.lang.ClassNotFoundException: org.hibernate.ejb.HibernatePersistence with a root cause of Caused by: java.lang.NoClassDefFoundError: org/hibernate/ejb/HibernatePersistence
My maven deps do include the relevant Hibernate stuff and I do see the jars are included in the output dir when running under studio. But mule classloader doesnt seem to be able to find them...or I'm clueless about what's needed.
I have tried several combinations of Hibernate and Spring-orm versions and currently am using latest of each:
<spring.version>4.0.0.RELEASE</spring.version>
<hibernate.version>4.2.2.Final</hibernate.version>
The relevant parts of my pom look like:
<dependencies>
...
<dependency>
<groupId>org.mule.modules</groupId>
<artifactId>mule-module-jpa</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator-annotation-processor</artifactId>
<version>4.1.0.Final</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.26</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
<plugins>
...
<plugin>
<groupId>org.mule.tools</groupId>
<artifactId>maven-mule-plugin</artifactId>
<version>1.9</version>
<extensions>true</extensions>
<configuration>
<copyToAppsDirectory>true</copyToAppsDirectory>
<inclusions>
<inclusion>
<groupId>org.mule.modules</groupId>
<artifactId>mule-module-jpa</artifactId>
</inclusion>
</inclusions>
</configuration>
</plugin>
</plugins>
And my simple mule config looks like:
<?xml version="1.0" encoding="UTF-8"?>
<mule version="CE-3.4.0"
xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:jpa="http://www.mulesoft.org/schema/mule/jpa"
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"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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/1.0/mule-jpa.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
">
<spring:beans>
<spring:bean id="datasource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<spring:property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<spring:property name="url" value="jdbc:mysql://localhost:3306/test"/>
<spring:property name="username" value="XXXX"/>
<spring:property name="password" value="XXXX"/>
</spring:bean>
<spring:bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<spring:property name="dataSource" ref="datasource"/>
<spring:property name="jpaVendorAdapter">
<spring:bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<spring:property name="showSql" value="true"/>
<spring:property name="generateDdl" value="false"/>
<spring:property name="databasePlatform" value="org.hibernate.dialect.MySQL5Dialect"/>
</spring:bean>
</spring:property>
</spring:bean>
</spring:beans>
<jpa:config name="Java_Persistence_API" entityManagerFactory-ref="entityManagerFactory" doc:name="Java Persistence API"/>
<flow name="jpa_test2Flow1" doc:name="jpa_test2Flow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="query" doc:name="HTTP"/>
<logger level="INFO" doc:name="Logger"/>
<jpa:find config-ref="Java_Persistence_API" entityClass="domain.Dog" id-ref="#[message.payload.name]" doc:name="Java Persistence API"/>
</flow>
</mule>
The complete exception I get is:
Exception in thread "main" org.mule.module.launcher.DeploymentInitException: ClassNotFoundException: org.hibernate.ejb.HibernatePersistence at org.mule.module.launcher.application.DefaultMuleApplication.init(DefaultMuleApplication.java:219) at org.mule.module.launcher.application.ApplicationWrapper.init(ApplicationWrapper.java:64) at org.mule.module.launcher.DefaultMuleDeployer.deploy(DefaultMuleDeployer.java:47) at org.mule.tooling.server.application.ApplicationDeployer.run(ApplicationDeployer.java:58) at org.mule.tooling.server.application.ApplicationDeployer.main(ApplicationDeployer.java:91) Caused by: org.mule.api.config.ConfigurationException: Error creating bean with name 'entityManagerFactory' defined in URL [file:/home/matthew/MuleStudio/workspace/.mule/apps/jpa_test2/jpa_test2.xml]: Cannot create inner bean 'org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter#495b317b' of type [org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter] while setting bean property 'jpaVendorAdapter'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter#495b317b' defined in URL [file:/home/matthew/MuleStudio/workspace/.mule/apps/jpa_test2/jpa_test2.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/hibernate/ejb/HibernatePersistence (org.mule.api.lifecycle.InitialisationException) (org.mule.api.config.ConfigurationException) at org.mule.config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:52) at org.mule.config.builders.AbstractResourceConfigurationBuilder.configure(AbstractResourceConfigurationBuilder.java:78) at org.mule.context.DefaultMuleContextFactory.createMuleContext(DefaultMuleContextFactory.java:84) at org.mule.module.launcher.application.DefaultMuleApplication.init(DefaultMuleApplication.java:207) ... 4 more Caused by: org.mule.api.config.ConfigurationException: Error creating bean with name 'entityManagerFactory' defined in URL [file:/home/matthew/MuleStudio/workspace/.mule/apps/jpa_test2/jpa_test2.xml]: Cannot create inner bean 'org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter#495b317b' of type [org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter] while setting bean property 'jpaVendorAdapter'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter#495b317b' defined in URL [file:/home/matthew/MuleStudio/workspace/.mule/apps/jpa_test2/jpa_test2.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/hibernate/ejb/HibernatePersistence (org.mule.api.lifecycle.InitialisationException) at org.mule.config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:52) at org.mule.config.builders.AbstractResourceConfigurationBuilder.configure(AbstractResourceConfigurationBuilder.java:78) at org.mule.config.builders.AutoConfigurationBuilder.autoConfigure(AutoConfigurationBuilder.java:101) at org.mule.config.builders.AutoConfigurationBuilder.doConfigure(AutoConfigurationBuilder.java:57) at org.mule.config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:46) ... 7 more Caused by: org.mule.api.lifecycle.InitialisationException: Error creating bean with name 'entityManagerFactory' defined in URL [file:/home/matthew/MuleStudio/workspace/.mule/apps/jpa_test2/jpa_test2.xml]: Cannot create inner bean 'org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter#495b317b' of type [org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter] while setting bean property 'jpaVendorAdapter'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter#495b317b' defined in URL [file:/home/matthew/MuleStudio/workspace/.mule/apps/jpa_test2/jpa_test2.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/hibernate/ejb/HibernatePersistence at org.mule.registry.AbstractRegistry.initialise(AbstractRegistry.java:117) at org.mule.config.spring.SpringXmlConfigurationBuilder.createSpringRegistry(SpringXmlConfigurationBuilder.java:119) at org.mule.config.spring.SpringXmlConfigurationBuilder.doConfigure(SpringXmlConfigurationBuilder.java:73) at org.mule.config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:46) ... 11 more Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in URL [file:/home/matthew/MuleStudio/workspace/.mule/apps/jpa_test2/jpa_test2.xml]: Cannot create inner bean 'org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter#495b317b' of type [org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter] while setting bean property 'jpaVendorAdapter'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter#495b317b' defined in URL [file:/home/matthew/MuleStudio/workspace/.mule/apps/jpa_test2/jpa_test2.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/hibernate/ejb/HibernatePersistence at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:282) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:121) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1391) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1132) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1117) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:922) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) at org.mule.config.spring.SpringRegistry.doInitialise(SpringRegistry.java:89) at org.mule.registry.AbstractRegistry.initialise(AbstractRegistry.java:109) ... 14 more Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter#495b317b' defined in URL [file:/home/matthew/MuleStudio/workspace/.mule/apps/jpa_test2/jpa_test2.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/hibernate/ejb/HibernatePersistence at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1011) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:957) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:490) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:271) ... 28 more Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/hibernate/ejb/HibernatePersistence at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:163) at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1004) ... 32 more Caused by: java.lang.NoClassDefFoundError: org/hibernate/ejb/HibernatePersistence at org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter.(HibernateJpaVendorAdapter.java:57) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:526) at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:148) ... 34 more Caused by: java.lang.ClassNotFoundException: org.hibernate.ejb.HibernatePersistence at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at org.mule.module.launcher.FineGrainedControlClassLoader.findClass(FineGrainedControlClassLoader.java:179) at org.mule.module.launcher.FineGrainedControlClassLoader.loadClass(FineGrainedControlClassLoader.java:123) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) ... 40 more
I am starting to think that this module is not ready for usage despite it being available as a cloud connector from inside studio?