gpt4 book ai didi

HibernatePersistence 类未发现 JPA + Hibernate + OSGI 的异常

转载 作者:行者123 更新时间:2023-12-01 08:28:19 24 4
gpt4 key购买 nike

我在 Equinox 环境中遇到了 jpa + hibernate 的问题。我遇到了异常

    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter#53308cd' defined in OSGi resource[classpath:/spring/gdl-commons-db-jpa-context.xml|bnd.id=177|bnd.sym=gdl-open-domain]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/hibernate/ejb/HibernatePersistence
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1037)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:983)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:487)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:271)
... 34 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/hibernate/ejb/HibernatePersistence
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:163)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1030)
... 38 common frames omitted
Caused by: java.lang.NoClassDefFoundError: org/hibernate/ejb/HibernatePersistence
at org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter.<init>(HibernateJpaVendorAdapter.java:57)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:148)
... 40 common frames omitted

请在下面找到我的 jar 详细信息

    com.springsource.javassist-3.15.0.GA.jar                           
hibernate-core-3.3.2.GA.jar
com.springsource.javax.transaction-1.1.0.jar
hibernate-core-4.1.9.Final.jar
com.springsource.org.hibernate-4.1.0.Final.jar
com.springsource.org.hibernate.annotations.common-3.3.0.ga.jar
hibernate-entitymanager-3.4.0.GA.jar
com.springsource.org.hibernate.annotations.common-4.0.1.Final.jar
hibernate-entitymanager-4.1.9.Final.jar
hibernate-annotations-3.4.0.GA.jar
hibernate-jpa-2.0-api-1.0.1.Final.jar
spring-data-commons-1.6.0.RELEASE.jar
hibernate-validator-4.0.2.GA.jar

我的 manifest.mf 是

    Import-Package: org.springframework.data.jpa.domain.support;version="[
1.3,2)",org.springframework.data.jpa.repository;version="[1.3,2)",org
.springframework.data.repository;version="[1.5,2)",javax.sql,org.apac
he.commons.pool;version="[1.5,2)",org.apache.commons.pool.impl;versio
n="[1.5,2)",org.springframework.orm.jpa.persistenceunit,org.springfra
mework.core.io,org.springframework.core.type.classreading,org.springf
ramework.core.io.support,org.springframework.core.type.filter,org.spr
ingframework.util,org.springframework.core.type,javax.persistence;version="1.0.1";jpa
="2.0",javassist.util.proxy;resolution:=optional,org.
hibernate,org.springframework.orm.jpa,org.hibernate.ejb,org.springfra
mework.orm.jpa.vendor,org.springframework.dao.annotation,org.springfr
amework.jmx.export.assembler,org.springframework.jmx.support,org.spri
ngframework.beans.factory.config,org.springframework.beans.factory.as
pectj,org.hibernate.proxy,org.springframework.aop.aspectj.autoproxy,o
rg.springframework.aop.interceptor,org.hibernate.ejb.connection,javax.persistence.criteria

Meta-Persistence: META-INF/persistence.xml
Spring-Context: spring/*.xml

请帮我解决这个类未发现异常。

谢谢,

gopy

已编辑:

我现在仍然面临问题,我正在使用 hibernate-release-4.3.7.Final,

好的,让我解释一下我的项目结构,并告诉我我缺少的地方,

目前我们的系统在这么多 jar 文件中只有一个 war 文件。所以我需要迁移到 osgi 并取出所有与业务相关的 jar 来设置模块概念。

所以最初我取出一些重要的库并转换为 bundle 。

让我们说,

Bundle_A 是一个主包,里面包含很多第三方依赖,包括我们应用相关的库 library_b、library_c 等。

从 Bundle_A 导入为 Bundle-ClassPath 的所有库,

library_b、library_c 拥有自己的 spring.xml 和一些从 Bundle_A 加载的配置

library_b,spring.xml 具有 JPARepositoryImpl 和配置,我们在 Bundle_A 中有一些存储库也引用 library_a 实现。似乎我遇到了 JPARepositoryImpl 类未正确加载之类的异常。找不到类异常。

请在下面找到一些异常(exception),

nested exception is java.lang.NoClassDefFoundError: com.domain.jpa.impl.MyRepositoryFactoryBean not found from bundle [My  Platform Domain (My--domain)]
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [org.springframework.data.jpa.domain.support.AuditingEntityListener] for bean with name 'org.springframework.data.jpa.domain.support.AuditingEntityListener' defined in null: problem with class file or dependent class; nested exception is java.lang.NoClassDefFoundError: org.springframework.data.jpa.domain.support.AuditingEntityListener not found from bundle [My Platform Domain (My--domain)]
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [com.domain.jpa.impl.MyRepositoryFactoryBean] for bean with name 'communicationSettingRepository' defined in null: problem with class file or dependent class; nested exception is java.lang.NoClassDefFoundError: com.domain.jpa.impl.MyRepositoryFactoryBean not found from bundle [My Platform Domain (My--domain)]
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [com.domain.jpa.impl.MyRepositoryFactoryBean]

......等

这是一个巨大的异常(exception),因为我有很多存储库,例如communicationSettingRepository,所以它打印所有存储库名称,例如

Error loading class [com.domain.jpa.impl.MyRepositoryFactoryBean] for bean with name 'repository' defined in null

异常结束

Caused by: java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
at sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:715)
at sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:522)
at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:348)
at sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:283)
at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:117)
at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:70)
at java.lang.Class.initAnnotationsIfNecessary(Class.java:3271)
at java.lang.Class.initAnnotationsIfNecessary(Class.java:3278)
at java.lang.Class.getAnnotation(Class.java:3219)
at java.lang.Class.isAnnotationPresent(Class.java:3232)
at org.hibernate.annotations.common.reflection.java.JavaAnnotationReader.isAnnotationPresent(JavaAnnotationReader.java:50)
at org.hibernate.annotations.common.reflection.java.JavaXAnnotatedElement.isAnnotationPresent(JavaXAnnotatedElement.java:60)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.syncAnnotatedClasses(Configuration.java:3780)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1411)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1846)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:852)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:845)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:398)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:844)
at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:152)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:67)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:288)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1571)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1509)
... 31 common frames omitted

希望你们能猜出实际问题吗?请帮我解决这个问题。

最佳答案

hibernate-entitymanager-4.1.9.Final.jar 应该是缺少的类。您的类路径中有多个版本的 hibernate 库。 3.x 和 4.x。建议你下载最新的hibernate version并将它们替换为当前的类路径 jar。

另外作为旁注 org/hibernate/ejb/HibernatePersistence 已被弃用。如果您使用 JPA 标准,org.hibernate.jpa.HibernatePersistenceProvider 是正确的持久性提供程序。

关于HibernatePersistence 类未发现 JPA + Hibernate + OSGI 的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27591335/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com