Spring.Net 2, NHibernate 4 Error "Could not load type from string value 'Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate'." - nhibernate

I'm attempting to upgrade a project from Spring.Net 1.3.2, NHibernate 3.2 to Spring.Net 2, NHibernate 4.
I get the error "Could not load type from string value 'Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate'." When I try to run.
My log shows:
System.Configuration.ConfigurationErrorsException: Error creating context 'spring.root': Could not load type from string value 'Spring.Data.NHibernate.HibernateTransactionManager, Spring.Data.NHibernate'. ---> Spring.Objects.Factory.ObjectCreationException: Error thrown by a dependency of object 'transactionAdvisor' defined in 'file [C:\Users\...\Project.Web\Config\transaction.aop.xml] line 7' : Initialization of object failed : Cannot resolve type [Spring.Data.NHibernate.HibernateTransactionManager, Spring.Data.NHibernate] for object with name 'transactionManager' defined in file [C:\Users\...\Project.Web\Config\hibernate.cfg.xml] line 45
while resolving 'TransactionInterceptor' to 'transactionInterceptor' defined in 'file [C:\Users\...\Project.Web\Config\transaction.aop.xml] line 12' ---> Spring.Core.CannotLoadObjectTypeException: Cannot resolve type [Spring.Data.NHibernate.HibernateTransactionManager, Spring.Data.NHibernate] for object with name 'transactionManager' defined in file [C:\Users\...\Project.Web\Config\hibernate.cfg.xml] line 45 ---> System.TypeLoadException: Could not load type from string value 'Spring.Data.NHibernate.HibernateTransactionManager, Spring.Data.NHibernate'.
at Spring.Core.TypeResolution.TypeResolver.Resolve(String typeName) in c:\_prj\spring-net\src\Spring\Spring.Core\Core\TypeResolution\TypeResolver.cs:line 81
If I just open a cs file and create a Spring.Data.NHibernate.LocalSessionFactoryObject it looks fine, and the namespace is correct.
I did change the references due to version changes. Here's what I have now:
transaction.aop.xml
<object id="transactionAdvisor" type="Spring.Transaction.Interceptor.TransactionAttributeSourceAdvisor, Spring.Data">
<property name="TransactionInterceptor" ref="transactionInterceptor"/>
</object>
<!-- Transaction Interceptor -->
<object id="transactionInterceptor" type="Spring.Transaction.Interceptor.TransactionInterceptor, Spring.Data">
<property name="TransactionManager" ref="transactionManager"/>
<property name="TransactionAttributeSource" ref="attributeTransactionAttributeSource"/>
</object>
<object id="attributeTransactionAttributeSource" type="Spring.Transaction.Interceptor.AttributesTransactionAttributeSource, Spring.Data">
</object>
hibernate.cfg.xml
<object id="placeholder_db_settings" type="Spring.Objects.Factory.Config.PropertyPlaceholderConfigurer, Spring.Core">
<property name="ConfigSections" value="databaseSettings,appSettings,emailSettings"/>
</object>
<db:provider id="DbProvider" provider="SqlServer-2.0" connectionString="Data Source=${db.datasource};Database=${db.database};User ID=${db.user};Password=${db.password};Connect Timeout=${db.connectTimeout}"/>
<object id="hibernateSessionFactory" type="Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate">
<property name="DbProvider" ref="DbProvider"/>
<property name="MappingAssemblies">
<list>
<value>IBB.BusinessNet.Services</value>
</list>
</property>
<property name="HibernateProperties">
<dictionary>
<entry key-ref="connection.provider" value-ref="NHibernate.Connection.DriverConnectionProvider"/>
<entry key-ref="show_sql" value-ref="false"/>
<entry key-ref="dialect" value-ref="NHibernate.Dialect.MsSql2008Dialect"/>
<entry key-ref="connection.driver_class" value-ref="NHibernate.Driver.SqlClientDriver"/>
<entry key-ref="connection.pool_size" value-ref="10"/>
<entry key-ref="query.substitutions" value-ref="true 1, false 0, yes 'Y', no 'N'"/>
<entry key-ref="use_outer_join" value-ref="true"/>
<entry key-ref="command_timeout" value-ref="840" />
<entry key-ref="cache.provider_class" value-ref="NHibernate.Caches.SysCache2.SysCacheProvider,NHibernate.Caches.SysCache2" />
</dictionary>
</property>
<property name="ExposeTransactionAwareSessionFactory" value="true" />
</object>
<object id="transactionManager" type="Spring.Data.NHibernate.HibernateTransactionManager, Spring.Data.NHibernate">
<property name="DbProvider" ref="DbProvider"/>
<property name="SessionFactory" ref="hibernateSessionFactory"/>
</object>
<object id="MyHibernateTemplate" type="Spring.Data.NHibernate.Generic.HibernateTemplate">
<property name="SessionFactory" ref="hibernateSessionFactory" />
<property name="TemplateFlushMode" value="Auto" />
<property name="AllowCreate" value="true" />
<property name="CacheQueries" value="true" />
</object>
<object id="HibernateTemplate" type="Spring.Data.NHibernate.HibernateTemplate">
<property name="SessionFactory" ref="hibernateSessionFactory" />
<property name="TemplateFlushMode" value="Auto" />
<property name="AllowCreate" value="true" />
<property name="CacheQueries" value="true" />
</object>
Of course everything is sanitized and trimmed to reduce space. I did not change the mapping hbm files because I didn't find anything saying I should.
I knocked Spring logging to DEBUG, fixed a few issues there. Changing NHibernate to DEBUG doesn't add any logging because it's not getting that far. Spring loads everything else fine. The hibernate.cfg.xml output DEBUG messages with "Ignoring object class loading failure for object X" all of them saying
"Could not load type from string value".
The first ERROR is "GetObjectInternal: error obtaining object transactionManager".
I've banged my head against the wall for hours trying to figure out why. I know there are folks out there who understand this stuff better than myself and can point me in the right direction, so here's my call for help.

Bah, I keep wanting to use the namespace rather than the assembly name. The 2 lines in hibernate.cfg.xml needed to be the name of the DLL.
<object id="hibernateSessionFactory" type="Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate4">
...
<object id="transactionManager" type="Spring.Data.NHibernate.HibernateTransactionManager, Spring.Data.NHibernate4">

Related

Ignite SqlQuery for two clients

I use next process for my Ignite cache with third party persistence:
empty database
start two instances in server mode
start first instance in client mode.
The client in cycle
creates entities
reads entities by a simple SqlQuery
So far all right. All the code works properly.
Then I start second instance in client mode. The code is the same.
The second client also in cycle
creates entities
reads entities by the SqlQuery
And the second client gets empty ResultSet. While the first client still reads the data properly. BTW. Both clients can get entities by keys.
Off course all the data in memory.
So why the second client can't read by SqlQuery?
Three options of code are below. All of them work identically: The first started client always gets correct result. The second started client always gets empty ResultSet.
SqlQuery<EntryKey, Entry> sql = new SqlQuery<>(Entry.class, "accNumber = ?");
sql.setArgs(number);
List<Cache.Entry<EntryKey, Entry>> res = entryCache.query(sql).getAll();
...
SqlFieldsQuery sql = new SqlFieldsQuery("select d_c, summa from Entry where accNumber = ?");
sql.setArgs(number);
List<List<?>> res = entryCache.query(sql).getAll();
...
SqlQuery<BinaryObject, BinaryObject> query = new SqlQuery<>(Entry.class, "accNumber = ?");
QueryCursor<Cache.Entry<BinaryObject, BinaryObject>> entryCursor = binaryEntry
.query(query.setArgs(number));
List<javax.cache.Cache.Entry<BinaryObject, BinaryObject>> res = entryCursor.getAll();
XML configuration is below:
<bean class="org.apache.ignite.configuration.CacheConfiguration">
<!-- Set a cache name. -->
<property name="name" value="entryCache" />
<!-- Set cache mode. -->
<property name="cacheMode" value="PARTITIONED" />
<property name="atomicityMode" value="TRANSACTIONAL" />
<!-- Number of backup nodes. -->
<property name="backups" value="1" />
<property name="cacheStoreFactory">
<bean class="javax.cache.configuration.FactoryBuilder"
factory-method="factoryOf">
<constructor-arg
value="ru.raiffeisen.cache.store.jdbc.CacheJdbcEntryStore" />
</bean>
</property>
<property name="readThrough" value="true" />
<property name="writeThrough" value="true" />
<property name="queryEntities">
<list>
<bean class="org.apache.ignite.cache.QueryEntity">
<!-- Setting indexed type's key class -->
<property name="keyType"
value="ru.raiffeisen.cache.repository.EntryKey" />
<!-- Setting indexed type's value class -->
<property name="valueType" value="ru.raiffeisen.cache.repository.Entry" />
<!-- Defining fields that will be either indexed or queryable. Indexed
fields are added to 'indexes' list below. -->
<property name="fields">
<map>
<entry key="key.accNumber" value="java.lang.String" />
<entry key="key.d_c" value="ru.raiffeisen.cache.repository.EntryKey.DEB_CRE" />
<entry key="key.valuedate" value="java.util.Date" />
<entry key="summa" value="java.lang.Integer " />
</map>
</property>
<!-- Defining indexed fields. -->
<property name="indexes">
<list>
<!-- Single field (aka. column) index -->
<bean class="org.apache.ignite.cache.QueryIndex">
<constructor-arg value="key.accNumber" />
</bean>
</list>
</property>
</bean>
</list>
</property>
</bean>
In case of a Third party store, readThrough works only for key-value API, for SQL you need to run loadCache method before performing queries on Ignite.
If you want to use read from disk with persistence, I would recommend using Ignite native persistence store: https://apacheignite.readme.io/docs/distributed-persistent-store
Also, I see in you configuration:
<property name="indexedTypes" value="true" />
It's definitely a mistake, it should be configured like:
<property name="indexedTypes">
<list>
<value>java.lang.Integer</value>
<value>java.lang.Long</value>
</list>
</property>
IndexedTypes and QueryEntity configure the same things, actually, internally, IndexedTypes will create a configuration of QueryEntity. So, it's redundantly to configure both.
Thanks to everyone for suggestions.
I achieved an option which gives a stable and correct result.
Actually I moved the field accNumber from the key class to the value class. So now select is filtered against a primitive field of the value class.
Query configuration:
<bean class="org.apache.ignite.cache.QueryEntity">
<!-- Setting indexed type's key class -->
<property name="keyType"
value="ru.raiffeisen.cache.repository.EntryKey" />
<!-- Setting indexed type's value class -->
<property name="valueType" value="ru.raiffeisen.cache.repository.Entry" />
<!-- Defining fields that will be either indexed or queryable. Indexed
fields are added to 'indexes' list below. -->
<property name="fields">
<map>
<entry key="accNumber" value="java.lang.String" />
<entry key="key.d_c" value="ru.raiffeisen.cache.repository.EntryKey.DEB_CRE" />
<entry key="key.valuedate" value="java.util.Date" />
<entry key="summa" value="java.lang.Integer " />
</map>
</property>
<!-- Defining indexed fields. -->
<property name="indexes">
<list>
<!-- Single field (aka. column) index -->
<bean class="org.apache.ignite.cache.QueryIndex">
<constructor-arg value="accNumber" />
</bean>
</list>
</property>
</bean>

History of test results team city

I'm looking to get a history of test runs from teamcity by calling the rest apis.
So far I found:
http://teamcity.xyz.com/app/rest/builds/65602/statistics
But this will give only stats for one run.
I found below from Teamcity api documentation, but it is not clear where I should enter the multiple build numbers
http://teamcity:8111/httpAuth/app/rest/builds?locator=BUILDS_LOCATOR&fields=build(id,number,status,buildType(id,name,projectName),statistics(property(name,value)))
has anyone tried this before??
You can achieve this through a different avenue by using the buildTypes endpoint because the locator only supports a single id dimension.
e.g.
/httpAuth/app/rest/buildTypes/id:##BUILD_TYPE##/builds?fields=build(id,number,status,buildType(id,name,projectName),statistics(property(name,value)))
This will return data similar to the following
<builds>
<build id="185" number="1.0.0.2" status="SUCCESS">
<buildType id="Website_1BuildApplication" name="1 - Build Application" projectName="Website"/>
<statistics>
<property name="ArtifactsSize" value="4201093"/>
<property name="BuildArtifactsPublishingTime" value="921"/>
<property name="BuildCheckoutTime" value="377"/>
<property name="BuildDuration" value="21791"/>
<property name="BuildDurationNetTime" value="20493"/>
<property name="buildStageDuration:artifactsPublishing" value="952"/>
<property name="buildStageDuration:buildFinishing" value="15"/>
<property name="buildStageDuration:buildStepRUNNER_6" value="19313"/>
<property name="buildStageDuration:firstStepPreparation" value="219"/>
<property name="buildStageDuration:sourcesUpdate" value="496"/>
<property name="BuildTestStatus" value="1"/>
<property name="SuccessRate" value="1"/>
<property name="TimeSpentInQueue" value="6272"/>
</statistics>
</build>
<build id="183" number="1.0.0.1" status="SUCCESS">
<buildType id="Website_1BuildApplication" name="1 - Build Application" projectName="Website"/>
<statistics>
<property name="ArtifactsSize" value="4200811"/>
<property name="BuildArtifactsPublishingTime" value="297"/>
<property name="BuildCheckoutTime" value="19500"/>
<property name="BuildDuration" value="45123"/>
<property name="BuildDurationNetTime" value="25326"/>
<property name="buildStageDuration:artifactsPublishing" value="328"/>
<property name="buildStageDuration:buildFinishing" value="140"/>
<property name="buildStageDuration:buildStepRUNNER_6" value="23603"/>
<property name="buildStageDuration:firstStepPreparation" value="265"/>
<property name="buildStageDuration:sourcesUpdate" value="19516"/>
<property name="BuildTestStatus" value="1"/>
<property name="SuccessRate" value="1"/>
<property name="TimeSpentInQueue" value="234"/>
</statistics>
</build>
</builds>
Hope this helps

Display Hibernate SQL To Console (Spring)

I'm working with spring 3, hibernate 4. I'm trying to follow this tutorial http://www.mkyong.com/hibernate/hibernate-display-generated-sql-to-console-show_sql-format_sql-and-use_sql_comments/, but my hibernate configuration is different:
<?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:jee="http://www.springframework.org/schema/jee"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd">
<!-- JDBC Data Source. It is assumed you have MySQL running on localhost port 3306 with
username root and blank password. Change below if it's not the case -->
<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/project"/>
<property name="username" value="root"/>
<property name="password" value="1234"/>
<property name="validationQuery" value="SELECT 1"/>
<property name="show_sql" value="true" />
<property name="format_sql" value="true" />
<property name="use_sql_comments" value="true" />
</bean>
</beans>
And the properties show_sql, format_sql and use_sql_comments are not working this way. I get this exception:
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'show_sql' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'show_sql' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
Is there anyway to achieve the tutorial with the definition of the bean??
show_sql not a property of org.apache.commons.dbcp.BasicDataSource . You have to define it in session factory configuration.
like this
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="data" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.H2Dialect</prop>
<prop key="hibernate.current_session_context_class">thread</prop>
<prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean>
The simplest approach probably is to set following logger to DEBUG:
org.hibernate.SQL
If you use log4j, find / create a log4j.properties file on your classpath root and add
log4j.logger.org.hibernate.SQL=DEBUG
See here for more info about log4j properties: http://logging.apache.org/log4j/1.2/manual.html
As I'm using JEE 8 and JBoss EAP, I managed to got the SQL after adding this line:
-Dorg.jboss.as.logging.per-deployment=false
on the end of "VM arguments" (Server tab -> JBoss Properties -> Open lauch configuration).

error when running red5 application on windows

I made very sample application for red5
I set WEB-INF(red5-web.properties, red5-web.xml, web.xml)
when I runnig the red.bat I view in the debug this error code :
[INFO] [Launcher:/test] org.springframework.beans.factory.xml.XmlBeanDefi
nitionReader - Loading XML bean definitions from ServletContext resource [/WEB-I
NF/red5-web.xml]
Exception in thread "Launcher:/test" org.springframework.beans.factory.xm
l.XmlBeanDefinitionStoreException: Line 25 in XML document from ServletContext r
esource [/WEB-INF/red5-web.xml] is invalid; nested exception is org.xml.sax.SAXP
arseException; lineNumber: 25; columnNumber: 68; cvc-id.2: There are multiple oc
currences of ID value 'web.handler'
and my client can't connect to server :(
from your description its impossible to say exactly what you've done.
You might better start to use for example the existing demo application that ship with every release.
Sebastian
<?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:lang="http://www.springframework.org/schema/lang"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.0.xsd">
<bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="/WEB-INF/red5-web.properties" />
</bean>
<bean id="web.context" class="org.red5.server.Context"
autowire="byType" />
<bean id="web.scope" class="org.red5.server.WebScope"
init-method="register">
<property name="server" ref="red5.server" />
<property name="parent" ref="global.scope" />
<property name="context" ref="web.context" />
<property name="handler" ref="web.handler" />
<property name="contextPath" value="${webapp.contextPath}" />
<property name="virtualHosts" value="${webapp.virtualHosts}" />
</bean>
<bean id="web.handler" class="com.myapp.Application" />
</beans>
change the web.handler bean in your red5-web.xml file
<bean id="web.handler" class="com.myapp.Application"
singleton="true" autowire="byName" />
Check the other bean names also. The error you posted says same ID used for two or more beans.

Eclipselink & Spring Data

I am trying to implement a solution using a combination of eclipselink (2.4.0) and spring-data-jpa (1.1.0.RELEASE). However, every time I deploy the solution (Tomcat 7), I get the following exception:
Caused by: java.lang.IllegalArgumentException: No [ManagedType] was found for
the key class [com.acme.domain.entities.User] in the Metamodel - please
verify that the [Managed] class was referenced in persistence.xml using a
specific <class>com.acme.domain.entities.User</class> property or a global
<exclude-unlisted-classes>false</exclude-unlisted-classes> element.
It appears to occur when the repository autowiring takes place (code examples below):
Service class
#Component
public class UserDataService {
#Autowired
private UserRepository userRepository;
...
}
Entity class
package com.acme.domain.entities;
...
#Entity
#Table(name = "users")
public class User implements Serializable {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(name = "user_id")
private Integer id;
...
}
persistence.xml
<persistence-unit name="default" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>com.acme.domain.entities.User</class>
...
</persistence-unit>
Can this be due to some conflict between spring and eclipselink?
UPDATE:
Stacktrace...
[#|2012-07-31 16:25:02,317|ERROR|pool-2-thread-40|org.springframework.web.context.ContextLoader|Context initialization failed|#]
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDataService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.acme.data.repositories.UserRepository com.acme.data.services.UserDataService.userRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: No [ManagedType] was found for the key class [com.acme.domain.entities.User] in the Metamodel - please verify that the [Managed] class was referenced in persistence.xml using a specific <class>com.acme.domain.entities.User</class> property or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element.
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.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:609)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:469)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:897)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:873)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:958)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1599)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:680)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.acme.data.repositories.UserRepository com.acme.data.services.UserDataService.userRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: No [ManagedType] was found for the key class [com.acme.domain.entities.User] in the Metamodel - please verify that the [Managed] class was referenced in persistence.xml using a specific <class>com.acme.domain.entities.User</class> property or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element.
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:512)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:92)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:284)
... 27 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: No [ManagedType] was found for the key class [com.acme.domain.entities.User] in the Metamodel - please verify that the [Managed] class was referenced in persistence.xml using a specific <class>com.acme.domain.entities.User</class> property or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element.
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:305)
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:484)
... 29 more
Caused by: java.lang.IllegalArgumentException: No [ManagedType] was found for the key class [com.acme.domain.entities.User] in the Metamodel - please verify that the [Managed] class was referenced in persistence.xml using a specific <class>com.acme.domain.entities.User</class> property or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element.
at org.eclipse.persistence.internal.jpa.metamodel.MetamodelImpl.entityEmbeddableManagedTypeNotFound(MetamodelImpl.java:174)
at org.eclipse.persistence.internal.jpa.metamodel.MetamodelImpl.managedType(MetamodelImpl.java:489)
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)
... 37 more
I was able to solve my issue but it was another setup as the one above, i just add a few things i stumbled across until i was able to solve it in my SE-Environment:
Bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=338837 affects EclipseLink Version 2.2.0 and below versions. Mostly happening in Local-Environment (RESOURCE_LOCAL). A EclipseLink version-Upgrade or the following workaround may help:
<exclude-unlisted-classes>false</exclude-unlisted-classes>
Having multiple persistence.xml files in classpath (e.g. especially in 3th party JARs) that all define the same persistence-unit-name (above "default" may be very common). Try renaming your persistence-unit-name in this case as a first step
In case of renaming the persistence-unit-name worked but changing it back to the old value reproduces the problem there is either above mentioned 3th party JAR or old JARs of your own project beeing included to your build (e.g. refactoring/ renaming on project level or similar changed the structure so for example a maven build could still take old build artifacts from the repository)
Finaly when it comes to my setup (Spring-Standalone Application, no persistence.xml but tons of Spring-configurations because a custom company Framework is used) it showed that i just forgot to add the the entity-package of the custom framework-core when i wanted to run one of their service-implementations (Spring-Bean implementation) in my local project rather than having their service-implementation from a JAR-dependency. So make sure that you have all of the required entity packages listed for your EntityManagerFactory:
<bean id="customEntityManagerFactory" parent="abstractEntityManagerFactory">
<property name="dataSource" ref="dataSource"/>
<!-- Packages of EntityClasses -->
<property name="packagesToScan">
<list merge="true">
<value>ch.company.div1.foo.bar.model</value>
<value>ch.company.div1.foo.barnicle.model</value>
<value>ch.company.div2.we.help.model</value>
</list>
</property>
<property name="jpaProperties">
<props merge="true">
<prop key="eclipselink.target-database">org.eclipse.persistence.platform.database.SQLServerPlatform
</prop>
<prop key="javax.persistence.transactionType">RESOURCE_LOCAL</prop>
</props>
</property>
</bean>
In my case i forgot to add the model packagege with the used entitys of another division (that writes the custom framework core) of our company.
Good luck, that error's a beast :/
Not sure if you are having the same problem I had: trying to create 2 different entity factories... The exception is the same, so maybe this will help. Essentially this exception was happening when it was instantiating an Entity on the wrong EntityManagerFactory.
My project was running fine with a single database connection but when I added a second one EclipseLink was confused on where to instantiate my entities. After a few debug my conclusion was to remove the property "packagesToScan" from my root-context.xml and replace it with a "persistenceXmlLocation". In that XML, I listed every class I needed to be scanned and excluded everything else with "<exclude-unlisted-classes>"
Here is my full XML configuration that is currently working:
root-context.xml
<bean id="dataSource1" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url" value="jdbc:postgresql://server1.example.com:5432/db1" />
<property name="username" value="username" />
<property name="password" value="password" />
<property name="defaultAutoCommit" value="false" />
<property name="initialSize" value="5" />
<property name="maxIdle" value="5" />
<property name="validationQuery" value="SELECT 1" />
<property name="timeBetweenEvictionRunsMillis" value="600000" />
<property name="poolPreparedStatements" value="true" />
<property name="maxOpenPreparedStatements" value="10" />
</bean>
<bean id="dataSource2" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url" value="jdbc:postgresql://server2.example.com:5432/db2" />
<property name="username" value="user" />
<property name="password" value="password" />
<property name="defaultAutoCommit" value="false" />
<property name="initialSize" value="5" />
<property name="maxIdle" value="5" />
<property name="validationQuery" value="SELECT 1" />
<property name="timeBetweenEvictionRunsMillis" value="600000" />
<property name="poolPreparedStatements" value="true" />
<property name="maxOpenPreparedStatements" value="10" />
</bean>
<bean id="emf1" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource1" />
<property name="persistenceXmlLocation" value="classpath:META-INF/persistence1.xml" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
<property name="showSql" value="false" />
</bean>
</property>
<property name="jpaPropertyMap">
<map>
<entry key="eclipselink.weaving" value="false" />
<entry key="eclipselink.logging.level" value="WARNING" />
<entry key="eclipselink.logging.timestamp" value="false" />
<entry key="eclipselink.logging.session" value="false" />
<entry key="eclipselink.logging.thread" value="false" />
</map>
</property>
<property name="loadTimeWeaver">
<bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
</property>
</bean>
<bean id="emf2" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource2" />
<property name="persistenceXmlLocation" value="classpath:META-INF/persistence2.xml" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
<property name="showSql" value="false" />
</bean>
</property>
<property name="jpaPropertyMap">
<map>
<entry key="eclipselink.weaving" value="false" />
<entry key="eclipselink.logging.level" value="WARNING" />
<entry key="eclipselink.logging.timestamp" value="false" />
<entry key="eclipselink.logging.session" value="false" />
<entry key="eclipselink.logging.thread" value="false" />
</map>
</property>
<property name="loadTimeWeaver">
<bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
</property>
</bean>
<bean name="transaction1" class="org.springframework.orm.jpa.JpaTransactionManager" p:entity-manager-factory-ref="emf1" />
<bean name="transaction2" class="org.springframework.orm.jpa.JpaTransactionManager" p:entity-manager-factory-ref="emf2" />
<jpa:repositories base-package="org.myproject.repository1" transaction-manager-ref="transaction1" entity-manager-factory-ref="emf1" />
<jpa:repositories base-package="org.myproject.repository2" transaction-manager-ref="transaction2" entity-manager-factory-ref="emf2" />
<tx:annotation-driven />
persistence1.xml
<persistence-unit name="persistence1" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>org.myproject.repository1.Repo1</class>
<class>org.myproject.repository1.Repo2</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
</persistence-unit>
persistence2.xml
<persistence-unit name="persistence2" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>org.myproject.repository2.Repo1</class>
<class>org.myproject.repository2.Repo2</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
</persistence-unit>
So, this works for me...
Apparently specifying each "persistence.xml" location prevents classes that are meant for another EntityManagerFactory to be instantiated on the first "emf". In fact, this looks like a bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=338837. All I could figure out from my debugging is that without the "persistenceXmlLocation" ALL classes that are found with "packageScan" were instantiated on the first created "emf", the second "emf" was completely ignored.
Hope this helps. Good luck!
Add the package (com.acme.domain.entities) with entities to packagesToScan.
Set the PersistenceUnitName, instead of the persistenceXmlLocation
No persistence.xml needed.
factory.setPersistenceUnitName("dummy1");
factory.setPersistenceUnitName("dummy2");