I have a standalone GORM application based on grails 2.0 working with NO issues for a single datasource. The moment I introduce another gorm:sessionFactory referencing a second datasource, the application fails. Details below.
spring application context code for reference:
`
<bean id="dataSource_aaa" class="org.apache.commons.dbcp.BasicDataSource">
<property name="url" value="jdbc:mysql://localhost/aaa" />
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
</bean>
<bean id="aaaMessageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="messages" />
</bean>
<!-- Single gorm session factory works, either one, but both together fail -->
<gorm:sessionFactory base-package="com.aaa.entity"
data-source-ref="dataSource_aaa"
message-source-ref="aaaMessageSource">
<property name="hibernateProperties">
<util:map>
<entry key="hibernate.hbm2ddl.auto" value="update" />
<entry key="hibernate.connection.autocommit" value="false" />
<entry key="hibernate.show_sql" value="false" />
</util:map>
</property>
</gorm:sessionFactory>
<bean id="dataSource_bbb" class="org.apache.commons.dbcp.BasicDataSource">
<property name="url" value="jdbc:mysql://localhost/bbb" />
...
</bean>
<bean id="bbbMessageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="messages" />
</bean>
<!-- Single gorm session factory works, either one, but both together fail -->
<gorm:sessionFactory base-package="com.bbb.entity"
data-source-ref="dataSource_bbb"
message-source-ref="bbbMessageSource">
<property name="hibernateProperties">
<util:map>
<entry key="hibernate.hbm2ddl.auto" value="create-drop" />
<entry key="hibernate.connection.autocommit" value="false" />
<entry key="hibernate.show_sql" value="false" />
</util:map>
</property>
</gorm:sessionFactory>
`
Application tries to initialize spring bean container but notice the beans getting overridden as:
2013-12-04 16:21:20,091 INFO XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [spring/application-context.xml]
2013-12-04 16:21:20,323 INFO XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [spring/application-beans.xml]
2013-12-04 16:21:20,345 INFO XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [spring/application-config.xml]
2013-12-04 16:21:20,778 INFO DefaultListableBeanFactory - Overriding bean definition for bean 'grailsApplication': replacing [Generic bean: class [org.codehaus.groovy.grails.commons.DefaultGrailsApplication]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=initialise; destroyMethodName=null] with [Generic bean: class [org.codehaus.groovy.grails.commons.DefaultGrailsApplication]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=initialise; destroyMethodName=null]
2013-12-04 16:21:20,779 INFO DefaultListableBeanFactory - Overriding bean definition for bean 'gormEnhancingPostProcessor': replacing [Generic bean: class [org.codehaus.groovy.grails.orm.hibernate.cfg.GORMEnhancingBeanPostProcessor]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] with [Generic bean: class [org.codehaus.groovy.grails.orm.hibernate.cfg.GORMEnhancingBeanPostProcessor]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null]
2013-12-04 16:21:20,779 INFO DefaultListableBeanFactory - Overriding bean definition for bean 'transactionManager': replacing [Generic bean: class [org.codehaus.groovy.grails.orm.hibernate.GrailsHibernateTransactionManager]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] with [Generic bean: class [org.codehaus.groovy.grails.orm.hibernate.GrailsHibernateTransactionManager]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null]
2013-12-04 16:21:21,033 INFO ClassPathXmlApplicationContext - Bean 'org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0' of type [class org.springframework.transaction.annotation.AnnotationTransactionAttributeSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2013-12-04 16:21:21,035 INFO ClassPathXmlApplicationContext - Bean 'org.springframework.transaction.config.internalTransactionAdvisor' of type [class org.springframework.transaction.interceptor.BeanFactoryTransactionAttributeSourceAdvisor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2013-12-04 16:21:21,047 INFO DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#69f674: defining beans
And then fails with the exception:
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.aaa.entity.CategoryValidator': Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'domainClass' threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1423)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1128)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
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.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77)
at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:102)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:57)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:182)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:190)
at App.main(App.groovy:15)
Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'domainClass' threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:101)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:57)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1420)
... 22 more
I suspect the issue lies in not namespacing the beans being created via the two sessionFactories by Gorm: http://grepcode.com/file/repo1.maven.org/maven2/org.grails/grails-hibernate/2.1.1/org/codehaus/groovy/grails/orm/hibernate/cfg/GORMSessionFactoryDefinitionParser.java?av=f
This seems to also be referenced on the Grails bug list, but don't believe there's been a working resolution: http://jira.grails.org/browse/GRAILS-4507
Has anyone had success with standalone GORM application with multiple data sources ?
Any and all help appreciated to get me moving forward.
Update:
In despair, I have finally ended up creating 3 different spring application contexts. One each for the two gorm sessionFactories, and one for the application business logic dealing with these data sources to do the marshalling. This WORKS, with the obvious limitation of not being able to span a transactional operation across the data sources. Also adds some code noise which I'll try to cleanup.
If anyone has better suggestions, please, I'd much prefer a cleaner solution than this.
Related
I'm having the error that I think is connected to PostgreSQL-Tomcat connection. I was not able to locate the piece where I am mistaken:
My catalina.out:
23.10.2020 14:45:27.207 [localhost-startStop-1] WARN o.s.w.c.support.XmlWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.context.support.PropertySourcesPlaceholderConfigurer#0': Cannot resolve reference to bean 'CommonsConfigurationFactoryBean' while setting bean property 'properties'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'CommonsConfigurationFactoryBean' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'DatabaseConfiguration' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'psqlDataSource' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is javax.naming.NamingException: Could not create resource factory instance [Root exception is java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSourceFactory]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:334) ~[spring-beans-3.2.13.RELEASE.jar:3.2.13.RELEASE]
...........
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'CommonsConfigurationFactoryBean' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'DatabaseConfiguration' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'psqlDataSource' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is javax.naming.NamingException: Could not create resource factory instance [Root exception is java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSourceFactory]
.........
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'psqlDataSource' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is javax.naming.NamingException: Could not create resource factory instance [Root exception is java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSourceFactory]
My applicationcontext:
<?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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<bean id="psqlDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/freshSiteDS"/>
<property name="lookupOnStartup" value="true"/>
<property name="proxyInterface" value="javax.sql.DataSource"/>
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="psqlDataSource"/>
</bean>
<bean id="flyway" class="com.googlecode.flyway.core.Flyway" init-method="migrate" depends-on="psqlDataSource">
<property name="dataSource" ref="psqlDataSource"/>
<property name="initOnMigrate" value="true"/>
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="psqlDataSource" />
</bean>
<bean id="namedJdbcTemplate" class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">
<constructor-arg ref="psqlDataSource" />
</bean>
<bean id="objectMapper" class="org.codehaus.jackson.map.ObjectMapper">
<property name="propertyNamingStrategy" value="#{T(org.codehaus.jackson.map.PropertyNamingStrategy).CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES}" />
</bean>
<context:property-placeholder file-encoding="UTF-8" properties-ref="CommonsConfigurationFactoryBean" ignore-resource-not-found="true" ignore-unresolvable="true"/>
<bean name="CommonsConfigurationFactoryBean"
class="org.springmodules.commons.configuration.CommonsConfigurationFactoryBean">
<constructor-arg ref="DatabaseConfiguration"/>
</bean>
<bean name="DatabaseConfiguration"
class="org.apache.commons.configuration.DatabaseConfiguration" depends-on="flyway">
<constructor-arg type="javax.sql.DataSource" ref="psqlDataSource"/>
<constructor-arg index="1" value="st_application_properties"/>
<constructor-arg index="2" value="property_key"/>
<constructor-arg index="3" value="property_value"/>
</bean>
<import resource="kernel-context.xml"/>
<import resource="service-context.xml"/>
<import resource="security-context2.xml"/>
<import resource="ws-context.xml"/>
<import resource="settings-context.xml"/>
<import resource="migration-context.xml"/>
<import resource="search-context.xml"/>
</beans>
The JDBC driver is in /opt/tomcat/lib/postgresql-42.2.18.jar
Please, give some piece of advice
Working on customizing ChatMessageListeningEndpoint & ChatMessageSendingMessageHandler but facing issues like
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myNotificationListeningEndpoint' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: outputChannel is required
<int:channel id="gcmInboundNotificationChannel"/>
<int:channel id="gcmOutboundNotificationChannel"/>
<bean id="toGcmTransformer" class="com.test.cardhash.service.AndroidMessageTransformer"/>
<int:chain input-channel="gcmOutboundNotificationChannel">
<bean class="com.test.cardhash.service.MyMessageSendingMessageHandler">
<constructor-arg ref="gcmConnection" />
</bean>
</int:chain>
<int:transformer id="testTransformer" ref="toGcmTransformer" input-channel="gcmInboundNotificationChannel"
method="doTransform" output-channel="gcmOutboundNotificationChannel"/>
<int-xmpp:outbound-channel-adapter
id="gcmOutboundAdapter" channel="gcmOutboundNotificationChannel"
xmpp-connection="gcmConnection" auto-startup="true"/>
<int:chain input-channel="gcmInboundNotificationChannel">
<bean class="com.test.cardhash.service.MyNotificationListeningEndpoint">
<constructor-arg ref="gcmConnection" />
<property name="outputChannel" ref="gcmOutboundNotificationChannel" />
</bean>
</int:chain>
<int-xmpp:inbound-channel-adapter
id="gcmInboundAdapter" channel="gcmInboundNotificationChannel"
xmpp-connection="gcmConnection" extract-payload="true" auto-startup="true" />
I am new to spring Data JPA.I facing problem in loading bean without using ApplicationContext or ClassPathXmlApplicationContext.Because in my current project I have one old spring related jar which cannot be removed.Because of which my current "SpringContext.xml" cannot be loaded.Here is my code which prevent from loading SpringContext.xml
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("SpringContext.xml");
RegistrationBean registrationBean = (RegistrationBean)context.getBean("registrationBean");
Here is my RegistrationBean for my Repository
#Component
public class RegistrationBean {
#Autowired
private CreditorProfileRepository creditorProfileReposigtory;
public RegistrationBean(){
}
public CreditorProfileRepository getCreditorProfileReposigtory() {
return creditorProfileReposigtory;
}
public void setEmployeeReposigtory(CreditorProfileRepository creditorProfileReposigtory) {
this.creditorProfileReposigtory = creditorProfileReposigtory;
}
}
Here is my repository
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
#Repository
public interface CreditorProfileRepository extends CrudRepository <CreditorProfile, String>{
public CreditorProfile findBympcreditorprofileidpk(String mpcreditorprofileidpk);
}
So I taught of using constructor injection to load registrationBean in my application class.Here is my application class
public class CreateCreditorProfile implements ICreateCreditorProfile{
RegistrationBean repositoryRegistration;
CreateCreditorProfile(RegistrationBean repositoryRegistration){
this.repositoryRegistration=repositoryRegistration;
}
CreateCreditorProfile(){
this.repositoryRegistration=repositoryRegistration;
}
#Override
public void createCreditorProfile(CreditorProfileServiceDetails creditorProfileServiceDetails) {
CreditorProfile creditorProfile = new CreditorProfile();
creditorProfile.setcreditorprofileidpk("343243243");
creditorProfile.setpartyid("000005");
creditorProfile.setpartyname("Federico o Peluso");
repositoryRegistration.getCreditorProfileReposigtory().save(creditorProfile);
}
Here is my ApplicationContext.xml
<bean id="registrationBean" class="com.mi.bn.payment.persistence.RegistrationBean" scope="prototype" />
<bean id="CreateCreditorProfile" class="com.mi.bn.paymen.persistence.CreateCreditorProfile" scope="prototype" >
<constructor-arg name="repositoryRegistration" ref="registrationBean" />
</bean>
<bean id="creditorsProfileConfiguration" class="com.mi.bn.payment.domain.configuration.CreditorsProfileConfiguration" scope="prototype">
<constructor-arg name="creater" ref="CreateCreditorProfile" />
</bean>
Here is my SpringContext.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:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:util="http://www.springframework.org/schema/util"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.0.xsd">
<!-- For consider the using of annotations foe defining Spring Bean -->
<context:annotation-config />
<!-- For defining Spring Bean -->
<context:component-scan base-package="com.cs.ed.paymentmessaging.persistence" />
<!-- For bootstrapping the Spring Repository -->
<jpa:repositories base-package="com.cs.ed.paymentmessaging.persistence" />
<!-- Necessary to get the entity manager injected into the factory bean -->
<bean
class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" >
<property name="url" value="jdbc:db2://localhost:50000/DD23"/>
<property name="driverClassName" value="com.ibm.db2.jcc.DB2Driver"/>
<property name="username" value="db2admin"/>
<property name="password" value="Wasadm1n"/>
</bean>
<bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true"/>
<property name="generateDdl" value="true"/>
<property name="databasePlatform" value="org.hibernate.dialect.DB2Dialect"/>
</bean>
<!-- Entity Manager Factory -->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="SpringData"></property>
<property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- Transaction Manager -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<!-- Enable Transactional Manner -->
<tx:annotation-driven transaction-manager="transactionManager" />
But still it is my application class I get null pointer exception at
repositoryRegistration.getCreditorProfileReposigtory().save(creditorprofile)
So Please let me know workaround for this problem.
Here is stack trace
11:03:04,725 INFO [CommandExecuter] An Unexpected Error Occurred An Unexpected Error Occurred java.lang.NullPointerException
com.trapedza.bankfusion.core.BankFusionException: An Unexpected Error Occurred java.lang.NullPointerException
at com.misys.bankfusion.subsystem.microflow.runtime.command.ExecuteMicroflowCommand.createBankFusionException(ExecuteMicroflowCommand.java:1224)
at com.misys.bankfusion.subsystem.microflow.runtime.command.ExecuteMicroflowCommand.execute(ExecuteMicroflowCommand.java:674)
at com.misys.bankfusion.command.impl.AbstractCommand.execute(AbstractCommand.java:596)
at com.trapedza.bankfusion.servercommon.commands.AbstractCommand.execute(AbstractCommand.java:392)
at com.misys.bankfusion.command.impl.CommandExecuter.executeCommand(CommandExecuter.java:435)
at com.misys.bankfusion.controller.ExecutionModeHelper.executeDirect(ExecutionModeHelper.java:142)
at com.misys.bankfusion.controller.ExecutionModeHelper.executeCommand(ExecutionModeHelper.java:121)
at com.misys.bankfusion.controller.ExecutionController.executeCommand(ExecutionController.java:121)
at com.misys.bankfusion.controller.CommandUtils.executeCommand(CommandUtils.java:66)
at com.misys.bankfusion.uxp.plugin.BankFusionServicePlugin.processOtherRequests(BankFusionServicePlugin.java:799)
at com.misys.bankfusion.uxp.plugin.BankFusionServicePlugin.executeService(BankFusionServicePlugin.java:191)
at com.misys.uxp.container.servlet.UXServlet.service(UXServlet.java:104)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.NullPointerException
at com.misys.bankfusion.paymentmessaging.persistence.CreateCreditorProfile.createCreditorProfile(CreateCreditorProfile.java:65)
at com.misys.bankfusion.paymentmessaging.domain.configuration.CreditorsProfileConfiguration.createCreditorProfile(CreditorsProfileConfiguration.java:34)
at com.misys.bankfusion.paymentmessaging.controller.fatom.MaintainCreditorProfiles.process(MaintainCreditorProfiles.java:46)
Your RegistrationBean seems not to be autowired:
public class CreateCreditorProfile implements ICreateCreditorProfile{
#Autowired
RegistrationBean repositoryRegistration;
...
}
Regarding your question why the constructor call is not working, as far as I can see there are 2 context.xml declarations - ApplicationContext.xml and SpringContext.xml. You need to load both of them:
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"SpringContext.xml","ApplicationContext.xml");
Or you can import the Application.xml inside the SpringContext.xml
<import resource="ApplicationContext.xml" />
Both ways should result in loading your beans properly.
I am trying to integrate Hibernate with Mule. Does Mule support Hibernate Transport ?
Hi #David,
I have tried to work with Mule JPA module. But I am facing Below issues. Kindly help me.
Here is my 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>
and this is my mflow file
<?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>
this is my entity class
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);
}
}
Getting below Exception Please let me know the solution.
Exception in thread "main"
org.mule.module.launcher.DeploymentInitException: IllegalAccessError:
tried to access method org.hibernate.engine.CascadeStyle.()V
from class org.hibernate.engine.EJB3CascadeStyle$1 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.main(ApplicationDeployer.java:127)
Caused by: org.mule.api.config.ConfigurationException: Error creating
bean with name 'entityManagerFactory' defined in class path resource
[applicationContext.xml]: Invocation of init method failed; nested
exception is java.lang.IllegalAccessError: tried to access method
org.hibernate.engine.CascadeStyle.()V from class
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)
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)
... 3 more Caused by: org.mule.api.config.ConfigurationException:
Error creating bean with name 'entityManagerFactory' defined in class
path resource [applicationContext.xml]: Invocation of init method
failed; nested exception is java.lang.IllegalAccessError: tried to
access method org.hibernate.engine.CascadeStyle.()V from class
org.hibernate.engine.EJB3CascadeStyle$1
(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)
... 6 more Caused by: org.mule.api.lifecycle.InitialisationException:
Error creating bean with name 'entityManagerFactory' defined in class
path resource [applicationContext.xml]: Invocation of init method
failed; nested exception is java.lang.IllegalAccessError: tried to
access method org.hibernate.engine.CascadeStyle.()V from class
org.hibernate.engine.EJB3CascadeStyle$1 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)
... 10 more Caused by:
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'entityManagerFactory' defined in class path
resource [applicationContext.xml]: Invocation of init method failed;
nested exception is java.lang.IllegalAccessError: tried to access
method org.hibernate.engine.CascadeStyle.()V from class
org.hibernate.engine.EJB3CascadeStyle$1 at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1486)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:524)
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)
... 13 more Caused by: java.lang.IllegalAccessError: tried to access
method org.hibernate.engine.CascadeStyle.()V from class
org.hibernate.engine.EJB3CascadeStyle$1 at
org.hibernate.engine.EJB3CascadeStyle$1.(EJB3CascadeStyle.java:24)
at
org.hibernate.engine.EJB3CascadeStyle.(EJB3CascadeStyle.java:19)
at
org.hibernate.ejb.event.EJB3PersistEventListener.(EJB3PersistEventListener.java:19)
at
org.hibernate.ejb.EventListenerConfigurator.(EventListenerConfigurator.java:81)
at
org.hibernate.ejb.Ejb3Configuration.(Ejb3Configuration.java:136)
at
org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:130)
at
org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:225)
at
org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:308)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1545)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1483)
... 24 more
What about the JPA connector: http://www.mulesoft.org/connectors/jpa-connector ?
I have this little project that works with Hibernate + Spring JPA and I'm just trying to change Hibernate to EclipseLink. When I do that, my jUnit test case simply can't autowire the very same repository that works with Hibernate. I can't figure out what is wrong...
application-context.xml
<bean id="datasource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost/test" />
<property name="username" value="root" />
</bean>
<bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect" />
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="datasource" />
<property name="persistenceUnitName" value="persistenceEclipseLink" />
<property name="jpaDialect" ref="jpaDialect" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter" />
</property>
<property name="loadTimeWeaver">
<bean class="org.springframework.instrument.classloading.SimpleLoadTimeWeaver" />
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<jpa:repositories base-package="com.example.test.repositories"></jpa:repositories>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
persistence.xml
<persistence-unit name="persistenceHibernate"
transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="hibernate.show_sql" value="true" />
</properties>
</persistence-unit>
<persistence-unit name="persistenceEclipseLink"
transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>com.example.test.entities.Post</class>
</persistence-unit>
This will result in:
ERROR org.springframework.test.context.TestContextManager - Caught exception while allowing TestExecutionListener[org.springframework.test.context.support.DependencyInjectionTestExecutionListener#2c5af885] to prepare test instance [com.example.test.PostRepositoryTest#871fa83] org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.example.test.PostRepositoryTest': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.example.test.repositories.PostRepository com.example.test.PostRepositoryTest.repository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'postRepository': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: The type [null] is not the expected [ManagedType] for the key class [class com.example.test.entities.Post].
If I simply change my entityManagerFactory to the bellow, everything works (using Hibernate):
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="datasource" />
<property name="persistenceUnitName" value="persistenceHibernate" />
</bean>
Can anyone catch what am I doing wrong on the EclipseLink configuration?
Thanks in advance.
EDIT:
Here's my jUnit test case:
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration(locations="classpath:META-INF/application-context.xml")
public class PostRepositoryTest {
#Autowired
PostRepository repository;
#Test
public void test() {
Post post = new Post();
post.setPostTitle("title");
repository.save(post);
}
}
EDIT
Full stack trace:
3601 [main] ERROR org.springframework.test.context.TestContextManager - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener#6077e77a] to prepare test instance [com.example.test.PostRepositoryTest#2d2e3a2c]
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.example.test.PostRepositoryTest': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.example.test.repositories.PostRepository com.example.test.PostRepositoryTest.repository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'postRepository': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: The type [null] is not the expected [ManagedType] for the key class [class com.example.test.entities.Post].
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:374)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:110)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:321)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:288)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:290)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.example.test.repositories.PostRepository com.example.test.PostRepositoryTest.repository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'postRepository': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: The type [null] is not the expected [ManagedType] for the key class [class com.example.test.entities.Post].
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:506)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:284)
... 26 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'postRepository': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: The type [null] is not the expected [ManagedType] for the key class [class com.example.test.entities.Post].
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:149)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:102)
at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1442)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:248)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:876)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:818)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:735)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:478)
... 28 more
Caused by: java.lang.IllegalArgumentException: The type [null] is not the expected [ManagedType] for the key class [class com.example.test.entities.Post].
at org.eclipse.persistence.internal.jpa.metamodel.MetamodelImpl.managedType(MetamodelImpl.java:424)
at org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation.<init>(JpaMetamodelEntityInformation.java:58)
at org.springframework.data.jpa.repository.support.JpaEntityInformationSupport.getMetadata(JpaEntityInformationSupport.java:65)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getEntityInformation(JpaRepositoryFactory.java:149)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:87)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:70)
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:137)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:125)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:41)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:142)
... 36 more
Post.java
#Entity
#Table(name="POST")
public class Post {
#Id
#GeneratedValue(strategy=GenerationType.IDENTITY)
#Column(name="ID")
Integer postId;
#Column(name="TITLE")
String postTitle;
(...getters and setters...)
}
PostRepository.java
import org.springframework.data.jpa.repository.JpaRepository;
import com.example.test.entities.Post;
public interface PostRepository extends JpaRepository<Post, Integer> {
}
Can you please include the full exception stack trace, (also the mappings for the Post class)
To use the same properties as you have in Hibernate,
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="hibernate.show_sql" value="true" />
in EclipseLink this would be,
<property name="eclipselink.target-database" value="MySQL" />
<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
<property name="eclipselink.logging.level" value="fine" />