我将应用程序(Spring + Hibernate + JPA)部署到Websphere应用程序服务器,并且应用程序连接到数据库版本Oracle 12c。
为了支持Oracle 12c DB,我需要Oracle12c Dialect和Websphere Application Server(8.5.5)支持JPA 2.0。
我看到Hibernate版本> 5仅提供Oracle12cDialect,而不提供JPA 2.0,而是提供(hibernate-jpa-2.1-api-1.0.0.Final.jar
)
V3.5至V4.2支持JPA 2.0(但是Oracle12cDialect不提供这些版本)
使用hibernate-entitymanager.5.0.7.Final.jar
时,在服务电话期间出现以下错误。
错误:
Caused by: java.lang.ClassCastException: com.ibm.websphere.persistence.PersistenceProviderImpl incompatible with javax.persistence.spi.PersistenceProvider
at javax.persistence.Persistence$1.isLoaded(Persistence.java:110) ~[hibernate-jpa-2.1-api-1.0.0.Final.jar:1.0.0.Final]
at org.hibernate.validator.internal.engine.resolver.JPATraversableResolver.isReachable(JPATraversableResolver.java:57) ~[hibernate-validator-4.3.0.Final.jar:4.3.0.Final]
at org.hibernate.validator.internal.engine.resolver.DefaultTraversableResolver.isReachable(DefaultTraversableResolver.java:130) ~[hibernate-validator-4.3.0.Final.jar:4.3.0.Final]
at org.hibernate.validator.internal.engine.resolver.SingleThreadCachedTraversableResolver.isReachable(SingleThreadCachedTraversableResolver.java:46) ~[hibernate-validator-4.3.0.Final.jar:4.3.0.Final]
at org.hibernate.validator.internal.engine.ValidatorImpl.isValidationRequired(ValidatorImpl.java:1221) ~[hibernate-validator-4.3.0.Final.jar:4.3.0.Final
如果我尝试保持应用程序提供的hibernate-jpa-2.1-api-1.0.0.Final.jar
范围,则会出现以下问题,因为AttributeConverter
类在Websphere JPA 2.0中不可用
ERROR o.s.web.servlet.DispatcherServlet - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax.persistence.AttributeConverter
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455) ~[spring-beans-3.1.3.RELEASE.jar:3.1.3.RELEASE]
Caused by: java.lang.NoClassDefFoundError: javax.persistence.AttributeConverter
at org.hibernate.boot.internal.MetadataBuilderImpl.<init>(MetadataBuilderImpl.java:127) ~[hibernate-core-5.0.7.Final.jar:5.0.7.Final]
at org.hibernate.boot.MetadataSources.getMetadataBuilder(MetadataSources.java:135) ~[hibernate-core-5.0.7.Final.jar:5.0.7.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:185) ~[hibernate-entitymanager-5.0.7.Final.jar:5.0.7.Final]
at org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:34) ~[hibernate-entitymanager-5.0.7.Final.jar:5.0.7.Final]
at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilder(HibernatePersistenceProvider.java:165) ~[hibernate-entitymanager-5.0.7.Final.jar:5.0.7.Final]
at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilder(HibernatePersistenceProvider.java:160) ~[hibernate-entitymanager-5.0.7.Final.jar:5.0.7.Final]
at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:135) ~[hibernate-entitymanager-5.0.7.Final.jar:5.0.7.Final]
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:50) ~[hibernate-entitymanager-5.0.7.Final.jar:5.0.7.Final]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:287) ~[spring-orm-3.1.3.RELEASE.jar:3.1.3.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310) ~[spring-orm-3.1.3.RELEASE.jar:3.1.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514) ~[spring-beans-3.1.3.RELEASE.jar:3.1.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452) ~[spring-beans-3.1.3.RELEASE.jar:3.1.3.RELEASE]
... 69 common frames omitted
Caused by: java.lang.ClassNotFoundException: javax.persistence.AttributeConverter
at java.net.URLClassLoader.findClass(URLClassLoader.java:600) ~[na:1.7.0]
at com.ibm.ws.bootstrap.ExtClassLoader.findClass(ExtClassLoader.java:240) ~[bootstrap.jar:WAS855.SERV1 [cf051507.01]]
at java.lang.ClassLoader.loadClassHelper(ClassLoader.java:941) ~[na:1.7.0]
at java.lang.ClassLoader.loadClass(ClassLoader.java:876) ~[na:1.7.0]
at com.ibm.ws.bootstrap.ExtClassLoader.loadClass(ExtClassLoader.java:133) ~[bootstrap.jar:WAS855.SERV1 [cf051507.01]]
at java.lang.ClassLoader.loadClass(ClassLoader.java:846) ~[na:1.7.0]
at com.ibm.ws.classloader.ProtectionClassLoader.loadClass(ProtectionClassLoader.java:62) ~[com.ibm.ws.runtime.jar:WAS855.SERV1 [cf051507.01]]
at com.ibm.ws.classloader.ProtectionClassLoader.loadClass(ProtectionClassLoader.java:58) ~[com.ibm.ws.runtime.jar:WAS855.SERV1 [cf051507.01]]
at com.ibm.ws.classloader.CompoundClassLoader.loadClass(CompoundClassLoader.java:617) ~[com.ibm.ws.runtime.jar:WAS855.SERV1 [cf051507.01]]
at java.lang.ClassLoader.loadClass(ClassLoader.java:846) ~[na:1.7.0]
at com.ibm.ws.classloader.CompoundClassLoader.loadClass(CompoundClassLoader.java:617) ~[com.ibm.ws.runtime.jar:WAS855.SERV1 [cf051507.01]]
at java.lang.ClassLoader.loadClass(ClassLoader.java:846) ~[na:1.7.0]
... 81 common frames omitted
如果我使用Hibernate版本支持JPA 2.0,则只需使用Oracle10gDialect。
休眠和webSphere成员有什么想法吗?
答案 0 :(得分:1)
该问题没有解决方案,您只能:
Websphere
版本升级到WAS 9.0
(当然,这很容易:))Oracle10gDialect
,除了特定于版本的详细信息(但我从未在简单的JPA
使用中遇到过任何问题),就可以与Oracle 12
一起使用。 P.S。有IBM note关于在JPA 2.1
上启用WAS 8.5.5
的说法,但是老实说,这种努力没有回报(没有更多的容器管理的持久性?谢谢)。