I have a problem that started happening today on a code that was previously working and I can't figure out the cause...
My code has 4 different database connections and they were apparently working... But now, if I have more than 1 configured by @EnableAutoConfiguration I start seeing all kinds of "No ManagedType" errors...
Here's two of the persistence configurations:
PersistenceMailserver.class
@Configuration
@EnableTransactionManagement
@EntityScan(basePackages = {"org.cidb.restentre.mailserver.entities"})
@EnableJpaRepositories(entityManagerFactoryRef = "emfMailserver", transactionManagerRef = "tmMailserver", basePackages = {"org.cidb.restentre.mailserver.repositories"})
class PersistenceMailserver {
@Primary
@Bean(name="dsMailserver")
DataSource dataSource() {
BasicDataSource dataSource = new BasicDataSource();
dataSource.setUrl("jdbc:mysql://host:3306");
dataSource.setUsername("user");
dataSource.setPassword("pass");
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
return dataSource;
}
@Primary
@Bean(name="emfMailserver")
LocalContainerEntityManagerFactoryBean entityManagerFactoryBean() {
LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
entityManagerFactoryBean.setDataSource(dataSource());
entityManagerFactoryBean.setJpaVendorAdapter(new EclipseLinkJpaVendorAdapter());
entityManagerFactoryBean.setPersistenceXmlLocation("classpath:META-INF/mailserver-persistence.xml");
Properties jpaProperties = new Properties();
jpaProperties.put("eclipselink.weaving", "false");
jpaProperties.put("eclipselink.logging.level", "SEVERE"); // SEVERE / FINEST
entityManagerFactoryBean.setJpaProperties(jpaProperties);
entityManagerFactoryBean.afterPropertiesSet();
return entityManagerFactoryBean;
}
@Primary
@Bean(name="tmMailserver")
JpaTransactionManager transactionManager() {
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(entityManagerFactoryBean().getNativeEntityManagerFactory());
return transactionManager;
}
}
PersistenceIntegrator.class
@Configuration
@EnableTransactionManagement
@EntityScan(basePackages = {"org.cidb.restentre.integrator.entities"})
@EnableJpaRepositories(entityManagerFactoryRef = "emfIntegrator", transactionManagerRef = "tmIntegrator", basePackages = {"org.cidb.restentre.integrator.repositories"})
class PersistenceIntegrator {
@Bean(name="dsIntegrator")
DataSource dataSource() {
BasicDataSource dataSource = new BasicDataSource();
dataSource.setUrl("jdbc:mysql://someotherhost:3306");
dataSource.setUsername("user");
dataSource.setPassword("pass");
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
return dataSource;
}
@Bean(name="emfIntegrator")
LocalContainerEntityManagerFactoryBean entityManagerFactoryBean() {
LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
entityManagerFactoryBean.setDataSource(dataSource());
entityManagerFactoryBean.setJpaVendorAdapter(new EclipseLinkJpaVendorAdapter());
entityManagerFactoryBean.setPersistenceXmlLocation("classpath:META-INF/integrator-persistence.xml");
Properties jpaProperties = new Properties();
jpaProperties.put("eclipselink.weaving", "false");
jpaProperties.put("eclipselink.logging.level", "SEVERE"); // SEVERE / FINEST
entityManagerFactoryBean.setJpaProperties(jpaProperties);
entityManagerFactoryBean.afterPropertiesSet();
return entityManagerFactoryBean;
}
@Bean(name="tmIntegrator")
JpaTransactionManager transactionManager() {
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(entityManagerFactoryBean().getNativeEntityManagerFactory());
return transactionManager;
}
}
You can see they are pretty much the same and they were working last night... But now, if I run this code I get:
Caused by: java.lang.IllegalArgumentException: No [ManagedType] was found for the key class [org.cidb.restentre.integrator.entities.IntegratorCustomer] in the Metamodel - please verify that the [Managed] class was referenced in persistence.xml using a specific <class>org.cidb.restentre.integrator.entities.IntegratorCustomer</class> property or a global <exclude-unlisted -classes>false</exclude-unlisted-classes> element.
at org.eclipse.persistence.internal.jpa.metamodel.MetamodelImpl.entityEmbeddableManagedTypeNotFound(MetamodelImpl.java:173)
at org.eclipse.persistence.internal.jpa.metamodel.MetamodelImpl.managedType(MetamodelImpl.java:495)
at org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation.<init>(JpaMetamodelEntityInformation.java:68)
at org.springframework.data.jpa.repository.support.JpaEntityInformationSupport.getMetadata(JpaEntityInformationSupport.java:67)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getEntityInformation(JpaRepositoryFactory.java:145)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:89)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:69)
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:172)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:239)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:225)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:92)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1625)
at org.springframework.beans.factory
Sometimes it complains about different classes when I run, which makes even harder to understand the probem...
The persistence.xml files are also pretty much the same (I wish I knew how to get rid of them, btw...)
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://ift.tt/UICAJV"
xmlns:xsi="http://ift.tt/ra1lAU"
xsi:schemaLocation="http://ift.tt/UICAJV http://ift.tt/O9YdEP" version="2.0">
<persistence-unit name="puMailserver" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
</persistence-unit>
</persistence>
All they have different from each other is the persistence-unit name...
Any ideas?
Thanks!
Aucun commentaire:
Enregistrer un commentaire