java 使用 Hibernate JPA 2.1 将应用程序部署到 IBM WebSphere 会产生 NullPointerException
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29476026/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Deploying application using Hibernate JPA 2.1 to IBM WebSphere gives NullPointerException
提问by npiani
We are trying to deploy a Java 7 Spring MVC application using Hibernate into an IBM WebSphere 8.5.5.2 server. The application runs fine on a Tomcat server, but we cannot get it running in WebSphere.
我们正在尝试使用 Hibernate 将 Java 7 Spring MVC 应用程序部署到 IBM WebSphere 8.5.5.2 服务器中。该应用程序在 Tomcat 服务器上运行良好,但我们无法在 WebSphere 中运行它。
The stack trace output is the following:
堆栈跟踪输出如下:
[3/26/15 13:49:53:552 MDT] 00000066 AutowiredAnno I org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor <init> JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
[3/26/15 13:49:54:299 MDT] 00000066 LocalContaine I org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean createNativeEntityManagerFactory Building JPA container EntityManagerFactory for persistence unit 'default'
[3/26/15 13:49:54:339 MDT] 00000066 LogHelper Z org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation HHH000204: Processing PersistenceUnitInfo [
name: default
...]
[3/26/15 13:49:54:536 MDT] 00000066 Version Z org.hibernate.Version logVersion HHH000412: Hibernate Core {4.3.7.Final}
[3/26/15 13:49:54:543 MDT] 00000066 Environment Z org.hibernate.cfg.Environment <clinit> HHH000206: hibernate.properties not found
[3/26/15 13:49:54:546 MDT] 00000066 Environment Z org.hibernate.cfg.Environment buildBytecodeProvider HHH000021: Bytecode provider name : javassist
[3/26/15 13:49:54:580 MDT] 00000066 JarInputStrea Z org.hibernate.jpa.boot.archive.internal.JarInputStreamBasedArchiveDescriptor visitArchive HHH015010: Unable to find file (ignored): bundleresource://130.fwk-1163147521/
java.lang.NullPointerException: in is null
at java.util.zip.ZipInputStream.<init>(ZipInputStream.java:111)
at java.util.zip.ZipInputStream.<init>(ZipInputStream.java:90)
at java.util.jar.JarInputStream.<init>(JarInputStream.java:87)
at java.util.jar.JarInputStream.<init>(JarInputStream.java:73)
at org.hibernate.jpa.boot.archive.internal.JarInputStreamBasedArchiveDescriptor.visitArchive(JarInputStreamBasedArchiveDescriptor.java:73)
at org.hibernate.jpa.boot.scan.spi.AbstractScannerImpl.scan(AbstractScannerImpl.java:72)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.scan(EntityManagerFactoryBuilderImpl.java:725)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:221)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:188)
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.<init>(SpringHibernateJpaPersistenceProvider.java:49)
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:49)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:343)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1627)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1564)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:540)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory.getObject(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:229)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:956)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:747)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
at com.ibm.ws.webcontainer.webapp.WebApp.notifyServletContextCreated(WebApp.java:1686)
at com.ibm.ws.webcontainer.webapp.WebAppImpl.initialize(WebAppImpl.java:414)
at com.ibm.ws.webcontainer.webapp.WebGroupImpl.addWebApplication(WebGroupImpl.java:88)
at com.ibm.ws.webcontainer.VirtualHostImpl.addWebApplication(VirtualHostImpl.java:169)
at com.ibm.ws.webcontainer.WSWebContainer.addWebApp(WSWebContainer.java:749)
at com.ibm.ws.webcontainer.WSWebContainer.addWebApplication(WSWebContainer.java:634)
at com.ibm.ws.webcontainer.component.WebContainerImpl.install(WebContainerImpl.java:426)
at com.ibm.ws.webcontainer.component.WebContainerImpl.start(WebContainerImpl.java:718)
at com.ibm.ws.runtime.component.ApplicationMgrImpl.start(ApplicationMgrImpl.java:1177)
at com.ibm.ws.runtime.component.DeployedApplicationImpl.fireDeployedObjectStart(DeployedApplicationImpl.java:1370)
at com.ibm.ws.runtime.component.DeployedModuleImpl.start(DeployedModuleImpl.java:639)
at com.ibm.ws.runtime.component.DeployedApplicationImpl.start(DeployedApplicationImpl.java:968)
at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplication(ApplicationMgrImpl.java:776)
at com.ibm.ws.runtime.component.ApplicationMgrImpl.run(ApplicationMgrImpl.java:2195)
at com.ibm.ws.security.auth.ContextManagerImpl.runAs(ContextManagerImpl.java:5474)
at com.ibm.ws.security.auth.ContextManagerImpl.runAsSystem(ContextManagerImpl.java:5600)
at com.ibm.ws.security.core.SecurityContext.runAsSystem(SecurityContext.java:255)
at com.ibm.ws.runtime.component.ApplicationMgrImpl.start(ApplicationMgrImpl.java:2200)
at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.start(CompositionUnitMgrImpl.java:446)
at com.ibm.ws.runtime.component.CompositionUnitImpl.start(CompositionUnitImpl.java:123)
at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.start(CompositionUnitMgrImpl.java:389)
at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.access0(CompositionUnitMgrImpl.java:117)
at com.ibm.ws.runtime.component.CompositionUnitMgrImpl$CUInitializer.run(CompositionUnitMgrImpl.java:995)
at com.ibm.wsspi.runtime.component.WsComponentImpl$_AsynchInitializer.run(WsComponentImpl.java:502)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1864)
[3/26/15 13:49:54:899 MDT] 00000066 Version Z org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit> HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
[3/26/15 13:49:55:511 MDT] 00000066 Enhance E CWWJP9992E: openjpa.Enhance: Error: The identity field defined in the com.company.model.KeyValueMapping Embeddable is not supported.
[3/26/15 13:49:55:837 MDT] 00000066 Dialect Z org.hibernate.dialect.Dialect <init> HHH000400: Using dialect: org.hibernate.dialect.SQLServer2008Dialect
[3/26/15 13:49:55:864 MDT] 00000066 LobCreatorBui Z org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
[3/26/15 13:49:56:071 MDT] 00000066 AnnotationCon W org.springframework.context.support.AbstractApplicationContext refresh Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in com.company.WebConfig: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax/persistence/Table.indexes()[Ljavax/persistence/Index;
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1568)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:540)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory.getObject(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:229)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:956)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:747)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
at com.ibm.ws.webcontainer.webapp.WebApp.notifyServletContextCreated(WebApp.java:1686)
at com.ibm.ws.webcontainer.webapp.WebAppImpl.initialize(WebAppImpl.java:414)
at com.ibm.ws.webcontainer.webapp.WebGroupImpl.addWebApplication(WebGroupImpl.java:88)
at com.ibm.ws.webcontainer.VirtualHostImpl.addWebApplication(VirtualHostImpl.java:169)
at com.ibm.ws.webcontainer.WSWebContainer.addWebApp(WSWebContainer.java:749)
at com.ibm.ws.webcontainer.WSWebContainer.addWebApplication(WSWebContainer.java:634)
at com.ibm.ws.webcontainer.component.WebContainerImpl.install(WebContainerImpl.java:426)
at com.ibm.ws.webcontainer.component.WebContainerImpl.start(WebContainerImpl.java:718)
at com.ibm.ws.runtime.component.ApplicationMgrImpl.start(ApplicationMgrImpl.java:1177)
at com.ibm.ws.runtime.component.DeployedApplicationImpl.fireDeployedObjectStart(DeployedApplicationImpl.java:1370)
at com.ibm.ws.runtime.component.DeployedModuleImpl.start(DeployedModuleImpl.java:639)
at com.ibm.ws.runtime.component.DeployedApplicationImpl.start(DeployedApplicationImpl.java:968)
at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplication(ApplicationMgrImpl.java:776)
at com.ibm.ws.runtime.component.ApplicationMgrImpl.run(ApplicationMgrImpl.java:2195)
at com.ibm.ws.security.auth.ContextManagerImpl.runAs(ContextManagerImpl.java:5474)
at com.ibm.ws.security.auth.ContextManagerImpl.runAsSystem(ContextManagerImpl.java:5600)
at com.ibm.ws.security.core.SecurityContext.runAsSystem(SecurityContext.java:255)
at com.ibm.ws.runtime.component.ApplicationMgrImpl.start(ApplicationMgrImpl.java:2200)
at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.start(CompositionUnitMgrImpl.java:446)
at com.ibm.ws.runtime.component.CompositionUnitImpl.start(CompositionUnitImpl.java:123)
at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.start(CompositionUnitMgrImpl.java:389)
at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.access0(CompositionUnitMgrImpl.java:117)
at com.ibm.ws.runtime.component.CompositionUnitMgrImpl$CUInitializer.run(CompositionUnitMgrImpl.java:995)
at com.ibm.wsspi.runtime.component.WsComponentImpl$_AsynchInitializer.run(WsComponentImpl.java:502)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1864)
Caused by: java.lang.NoSuchMethodError: javax/persistence/Table.indexes()[Ljavax/persistence/Index;
at org.hibernate.cfg.annotations.EntityBinder.processComplementaryTableDefinitions(EntityBinder.java:973)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:824)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3845)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3799)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1412)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1846)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.perform(EntityManagerFactoryBuilderImpl.java:852)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.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.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:343)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1627)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1564)
... 37 more
Thank you!
谢谢!
采纳答案by Gas
The javax/persistence/Table.indexes()
is from JPA 2.1, WebSphere Application Server traditional 8.5.5.2 is using by default JPA 2.0 (OpenJPA). If you want to use Hibernate you have to override the default provider - check this postfor more details.
的javax/persistence/Table.indexes()
是从2.1 JPA,WebSphere应用服务器传统8.5.5.2被默认JPA 2.0(OpenJPA中)使用。如果您想使用 Hibernate,您必须覆盖默认提供程序 - 查看此帖子了解更多详细信息。
UPDATE
更新
Yes, you are correct. You cannot override default provider in WebSphere traditional 8.5.5.x with JPA 2.1 as container relies on 2.0 api for initialization.
是的,你是对的。您不能使用 JPA 2.1 覆盖 WebSphere 传统 8.5.5.x 中的默认提供程序,因为容器依赖 2.0 api 进行初始化。
If you have to use 2.1 you may use it as application managed provider not container managed. So you would need to disable JPA for your application, check thisand instead of rely on container on injecting EntityManager, initialize it by your self using API.
如果您必须使用 2.1,您可以将其用作应用程序管理的提供程序,而不是容器管理的。所以你需要为你的应用程序禁用 JPA,检查这个,而不是依赖容器注入 EntityManager,使用 API 由你自己初始化它。
The other option would be to consider WebSphere Libertywhich supports JPA 2.1 (using EclipseLink) starting from version 8.5.5.6. It should be possible to change provider there since container supports 2.1, however I didn't have time to test it.
另一种选择是考虑从版本 8.5.5.6 开始支持 JPA 2.1(使用 EclipseLink)的WebSphere Liberty。由于容器支持 2.1,因此应该可以在那里更改提供程序,但是我没有时间对其进行测试。
You can also upgrade to WebSphere Application Server v9, recently released, which supports JPA 2.1.
您还可以升级到最近发布的 WebSphere Application Server v9,它支持 JPA 2.1。
回答by amicoderozer
I share what worked for me. Me and my team were able to deploy our application with Spring 4.2.4, Hibernate 5.1 and Hibernate JPA 2.1 in Websphere 8.5.5 and Websphere 7.
我分享对我有用的东西。我和我的团队能够在 Websphere 8.5.5 和 Websphere 7 中使用Spring 4.2.4、Hibernate 5.1 和 Hibernate JPA 2.1部署我们的应用程序。
The key to do this is to extract all the hibernate libraries and put them in a shared library folder in your server, create in your server configuration a new class loader with parent last order and assign to this class loader the shared library containing the hibernate libraries. Then you must change the Default Java Persistence API settingsto use the hibernate persistence provider and not the default WebSphere persistence provider. So the steps are the followings:
执行此操作的关键是提取所有休眠库并将它们放入服务器中的共享库文件夹中,在服务器配置中创建一个具有父级最后顺序的新类加载器,并将包含休眠库的共享库分配给此类加载器. 然后您必须更改默认 Java 持久性 API 设置以使用休眠持久性提供程序而不是默认 WebSphere 持久性提供程序。所以步骤如下:
Create a folder in your server and put in it all the hibernate libraries
Create the shared library in Websphere (Environment / Shared libraries)and set it to the path of the folder you just created on the server
On WebSphere click on your server and under Server Infrastructureclick on Java and Process Management / Class Loader. Click on Newand select the Parent Lastoption. Save
Click on the new class loader you just created and click on Shared library referenceson the right. Here add the shared library containing the Hibernate Libraries
Now under the section Container Settings of your server click on Container Services / Default Java Persistence API settings. Here you have to specify an alternate default persistence provider. See the image below.
Now compile your application and remove from the generated war the Hibernate libraries (see image 1). Then install it in the server.
在您的服务器中创建一个文件夹并将所有休眠库放入其中
在Websphere中创建共享库(Environment / Shared libraries),设置为刚才在服务器上创建的文件夹的路径
在 WebSphere 上单击您的服务器,然后在Server Infrastructure 下单击Java 和 Process Management/Class Loader。单击“新建”并选择“父上次”选项。保存
单击您刚刚创建的新类加载器,然后单击右侧的共享库引用。这里添加包含 Hibernate 库的共享库
现在在您的服务器的 Container Settings 部分下,单击Container Services/Default Java Persistence API settings。您必须在此处指定备用的默认持久性提供程序。见下图。
现在编译您的应用程序并从生成的War中删除 Hibernate 库(参见图1)。然后安装在服务器上。
In my case the application works like a charm also in WebSphere 7.
This procedure solves javax/persistence/Table.indexes()
error and all the other compilation error caused by libraries conflict between WebSphere and Hibernate.
在我的例子中,该应用程序在 WebSphere 7 中也像魅力一样工作。这个过程解决了javax/persistence/Table.indexes()
错误和所有其他由 WebSphere 和 Hibernate 之间的库冲突引起的编译错误。
Reference:
参考:
回答by Jeff Sheets
Thought I would share what worked for me. I was able to use JPA 2.1 and Hibernate 4.3.11 on Websphere 8.5.5.5 by using a custom PersistenceProviderResolver so that the Websphere classes do not interfere with Hibernate https://gist.github.com/jeffsheets/aec3e94870ef903ce7efe33e00563d3c
以为我会分享对我有用的东西。我能够通过使用自定义 PersistenceProviderResolver 在 Websphere 8.5.5.5 上使用 JPA 2.1 和 Hibernate 4.3.11,以便 Websphere 类不会干扰 Hibernate https://gist.github.com/jeffsheets/aec3e94870ef903ce7efe33e00563d
I based it off of a post found here https://hibernate.atlassian.net/browse/JPA-4
我基于在这里找到的帖子https://hibernate.atlassian.net/browse/JPA-4
回答by Mr.J4mes
I made it work with Spring Boot 2.1.4, Hibernate 5.3.9.Final and WAS 8.5.5without any server-level changes :). The steps are outlined in my article below. Still using JPA 2.1, didn't have to downgrade to JPA 2.0 at all.
我让它与Spring Boot 2.1.4、Hibernate 5.3.9.Final 和 WAS 8.5.5 一起工作,没有任何服务器级别的更改:)。我在下面的文章中概述了这些步骤。仍在使用 JPA 2.1,根本不必降级到 JPA 2.0。
回答by jumping_monkey
What worked for me is:
对我有用的是:
In the logs(copied from the OP's log), there is this:
在日志中(从 OP 的日志中复制),有这样的:
[3/26/15 13:49:54:339 MDT] 00000066 LogHelper Z org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation HHH000204: Processing PersistenceUnitInfo [
name: default
...]
If you notice, it's trying to use the defaultpersistence provider.
如果您注意到,它正在尝试使用默认的持久性提供程序。
As such, if we do not specify explicitly the persistence provider to use, Hibernate is going to use the WAS Persistence Provider(i.e OpenJPA in this case) - and in the case of WebLogic, EclipseLink.
因此,如果我们没有明确指定要使用的持久性提供程序,Hibernate 将使用 WAS Persistence Provider(即本例中的 OpenJPA)——在 WebLogic 的情况下,将使用 EclipseLink。
As WAS 8.5.5.x support only JPA 2.0(and JPA 1.0), this will not work and a bunch of errors will appear in the logs(...), such as those posted by the OP.
由于 WAS 8.5.5.x 仅支持 JPA 2.0(和 JPA 1.0),这将不起作用,并且日志中会出现一堆错误(...),例如 OP 发布的错误。
In order to solve it, i explicitly specified the third party persistence to Hibernate as per this post
为了解决这个问题,我按照这篇文章明确指定了 Hibernate 的第三方持久性
I hope this will help someone.
我希望这会帮助某人。