没有为Metamodel中的密钥类[entity class]找到[ManagedType]

时间:2014-06-04 03:20:33

标签: eclipselink spring-data-jpa glassfish-4 netbeans-8

我正在使用spring-data-jpa(1.3.2.RELEASE),eclipselink(2.5.1)通过netbeans(8.0)与glassfish服务器(4)和maven进行项目。

项目运行正常,直到正在运行的服务器中进行第二次部署。这是错误。

  

org.springframework.beans.factory.BeanCreationException:错误   用名称' appLanguageManagerSpringImp'创建bean:注入   自动连接依赖失败;

     

嵌套异常是   org.springframework.beans.factory.BeanCreationException:不能   autowire字段:私有com ...... AppLanguageRepository   COM ...... AppLanguageManagerSpringImp.languageRepo;

     

嵌套异常是   org.springframework.beans.factory.BeanCreationException:错误   使用名称' appLanguageRepository创建bean':FactoryBean抛出   对象创建异常;

     

嵌套异常是java.lang.IllegalArgumentException:否   找到了密钥类的[ManagedType]   [com.pixieuniverse.nostalgia.model.entity.EAppPrefLanguage]在   元模型 - 请验证是否引用了[Managed]类   persistence.xml使用特定的   com.pixieuniverse.nostalgia.model.entity.EAppPrefLanguage   财产或全球   虚假元素。

在调用以下

的弹出数据代码时生成错误
//org.springframework.context.annotation.AnnotationConfigApplicationContext
new AnnotationConfigApplicationContext(ApplicationConfig.class)

这是stackrace

java.lang.Exception: DEBUG STACK TRACE for PoolBackedDataSource.close().
    at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.close(AbstractPoolBackedDataSource.java:417)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.springframework.beans.factory.support.DisposableBeanAdapter.invokeCustomDestroyMethod(DisposableBeanAdapter.java:327)
    at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:253)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:510)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:486)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:455)
    at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1090)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:487)
    at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:73)
    at com.pixieuniverse.nostalgia.model.crud.spring.impl.ImpFactorySpring.<init>(ImpFactorySpring.java:28)
    at com.pixieuniverse.nostalgia.model.crud.ImpFactory.getInstance(ImpFactory.java:21)
    at com.pixieuniverse.nostalgia.vc.servlet.util.AppServletContextListener.contextInitialized(AppServletContextListener.java:30)
    at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:5362)
    at com.sun.enterprise.web.WebModule.contextListenerStart(WebModule.java:743)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:5898)
    at com.sun.enterprise.web.WebModule.start(WebModule.java:691)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:1041)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:1024)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:747)
    at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2278)
    at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1924)
    at com.sun.enterprise.web.WebApplication.start(WebApplication.java:139)
    at org.glassfish.internal.data.EngineRef.start(EngineRef.java:122)
    at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:291)
    at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:352)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:497)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:219)
    at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:491)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:527)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:523)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAs(Subject.java:356)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:522)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:546)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1423)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1500(CommandRunnerImpl.java:108)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1762)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1674)
    at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:534)
    at com.sun.enterprise.v3.admin.AdminAdapter.onMissingResource(AdminAdapter.java:224)
    at org.glassfish.grizzly.http.server.StaticHttpHandler.service(StaticHttpHandler.java:297)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:246)
    at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
    at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
    at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
    at java.lang.Thread.run(Thread.java:722)

...

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'appLanguageManagerSpringImp': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.pixieuniverse.nostalgia.model.crud.spring.repository.AppLanguageRepository com.pixieuniverse.nostalgia.model.crud.spring.impl.AppLanguageManagerSpringImp.languageRepo; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'appLanguageRepository': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: No [ManagedType] was found for the key class [com.pixieuniverse.nostalgia.model.entity.EAppPrefLanguage] in the Metamodel - please verify that the [Managed] class was referenced in persistence.xml using a specific <class>com.pixieuniverse.nostalgia.model.entity.EAppPrefLanguage</class> property or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element.
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:288)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1120)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.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.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:73)
    at com.pixieuniverse.nostalgia.model.crud.spring.impl.ImpFactorySpring.<init>(ImpFactorySpring.java:28)
    at com.pixieuniverse.nostalgia.model.crud.ImpFactory.getInstance(ImpFactory.java:21)
    at com.pixieuniverse.nostalgia.vc.servlet.util.AppServletContextListener.contextInitialized(AppServletContextListener.java:30)
    at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:5362)
    at com.sun.enterprise.web.WebModule.contextListenerStart(WebModule.java:743)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:5898)

这是我的persistance.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" ...>
  <persistence-unit name="PU">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <!-- Error generates with or without <exclude-unlisted-classes>false</exclude-unlisted-classes> -->
    <class>com.pixieuniverse.nostalgia.model.entity.EAppPrefLanguage</class>
    <class>com.pixieuniverse.nostalgia.model.entity.EAppPrefLoginType</class>
  </persistence-unit>
</persistence>

请轻松一点

修改

现在我删除了Persistance.xml并更新了代码,使其无需persistance.xml,但仍然出现相同的错误。

@Bean
@Autowired
public EntityManagerFactory entityManagerFactory(DataSource bcDataSource) {
    EclipseLinkJpaVendorAdapter vendorAdapter = new EclipseLinkJpaVendorAdapter();
    vendorAdapter.setDatabasePlatform("org.eclipse.persistence.platform.database.MySQLPlatform");
    vendorAdapter.setGenerateDdl(true);
    vendorAdapter.setShowSql(false);

    LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();

    factory.setPackagesToScan("com.pixieuniverse.nostalgia.model.entity");
    factory.setJpaVendorAdapter(vendorAdapter);
    factory.setDataSource(bcDataSource);

    Properties properties = new Properties();

    properties.setProperty("eclipselink.weaving", "false");

    factory.setJpaProperties(properties);
    factory.afterPropertiesSet();

    return factory.getObject();
}

有任何提示吗?

0 个答案:

没有答案