带有 JPA 2.1 的 Websphere 8.5

问题描述 投票:0回答:5

IBM 曾经有一个功能包将 JPA 2.0 放入 WAS 7 中。WAS 8.5.5 显然附带了 JPA 2.0。但我们有一个应用程序刚刚升级到 Hibernate 4,它需要 JPA 2.1。我找不到将 WAS 8.5 功能包推送到 JPA 2.1 的链接。

还有其他人在 WAS 8.5 中使用过 Hibernate 4 吗?如果是这样,怎么办?如果没有功能包,我们会在 javax.persistence 类上遇到 NoSuchMethodError。

hibernate jpa websphere
5个回答
12
投票

Hibernate 4.3.7.Final 可以在 Websphere Application Server 8.5.5 中使用,配置如下:

  • hibernate-jpa-2.1.jar
    打包到您的应用程序中,并将类加载器策略设置为 PARENT_LAST。

    Hibernate 4.3.7.Final 与 Websphere 8.5.5 提供的 JPA 2.0 API 不兼容

  • 设置 JVM 属性 com.ibm.websphere.persistence.ApplicationsExcludedFromJpaProcessing=* 以禁用 Websphere JPA 初始化。

    如果没有这个,您将在启动过程中看到

    SAXParseException
    ,因为 Websphere 会尝试根据 JPA 2.0 模式解析 persistence.xml。

由以下原因引起:org.xml.sax.SAXParseException:预期根元素{http://java.sun.com/xml/ns/persistence}持久性
        在 com.ibm.ws.jpa.management.JaxbUnmarshaller.startElement(JaxbUnmarshaller.java:310)
  • 在您的应用程序中应用解决问题 JPA-4

    报告该问题是因为使用 Hibernate 的 JPA 2 API 而不是 Webspheres JPA 1 API,而解决方法也适用于 Hibernate 的 JPA 2.1 API,但有一些细微的更改:

    您需要将

    HibernatePersistence
    替换为
    HibernatePersistenceProvider
    ,因为前者已被弃用。

    如果没有这个,您将在启动过程中看到

    ClassCastException
    ,因为 Hibernate 的 JPA 2.1 API 将加载所有
    PersistenceProvider
    类,包括在类路径中公开的 Websphere 类。

引起:java.lang.ClassCastException:com.ibm.websphere.persistence.PersistenceProviderImpl 与 javax.persistence.spi.PersistenceProvider 不兼容
        在 javax.persistence.Persistence$1.isLoaded(Persistence.java:110)
        在 org.hibernate.validator.internal.engine.resolver.JPATraversableResolver.isReachable(JPATraversableResolver.java:56)

5
投票

Hibernate 4.2.x 实现了 JPA 2.0 规范,我们在 WebSphere 8.5.5 中使用它没有任何问题。我们将 Hibernate JAR 打包到 WAR 中,并将 persistence.xml 中的提供程序属性设置为 org.hibernate.ejb.HibernatePersistence。

仅 Hibernate 4.3.x 需要 JPA 2.1,并且无法与 WebSphere 8.5.5 配合使用。


1
投票

我能够使用在 Java 8 上运行的 websphere 8.5.5.13 来做到这一点 通过创建一个包含

的共享库
  • hibernate-jpa-2.1-api-1.0.2.Final.jar

  • hibernate-core-4.3.11.Final.jar

一切都对我来说很好。


0
投票

我能够在 WebSphere 8.5 上运行 JPA 2.1,如下所示:

1-使应用程序类最后从 websphere 控制台加载父级

2- 添加 LocalContainerEntityManagerFactoryBean 如下:

    @Primary
    @Bean
    public LocalContainerEntityManagerFactoryBean entityManagerFactory(EntityManagerFactoryBuilder builder,
            DataSource dataSource) {
        LocalContainerEntityManagerFactoryBean em = builder.dataSource(dataSource).packages("com.myapp")
                .properties(jpaProperties()).build();
        JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
        em.setJpaVendorAdapter(vendorAdapter);
        return em;
    }

    protected Map<String, Object> jpaProperties() {
        Map<String, Object> props = new HashMap<>();
        props.put("hibernate.physical_naming_strategy", CamelCaseToUnderscoresNamingStrategy.class.getName());
        props.put("hibernate.implicit_naming_strategy", SpringImplicitNamingStrategy.class.getName());
        return props;
    }

-1
投票

您在 WebSphere 中使用您自己的持久性提供程序应该没有问题。我的建议是您在应用程序中打包 JPA 2.1 提供程序,并尝试将类加载器更改为最后一个父级加载器。在这种情况下,您不会使用 WebSphere 提供的默认 OpenJPA 2.0。相反,您将使用您选择的提供商。

http://www-01.ibm.com/support/knowledgecenter/api/content/SSAW57_8.5.5/com.ibm.websphere.nd.multiplatform.doc/ae/tejb_jpa3rdparty.html

http://www-01.ibm.com/support/knowledgecenter/SSAW57_8.5.5/com.ibm.websphere.nd.multiplatform.doc/ae/trun_classload_server.html?cp=SSAW57_8.5.5%2F3-8- 2-5-1&lang=zh

希望这有帮助。

来自 IBM 支持门户的另一篇相关文章:http://www-01.ibm.com/support/docview.wss?uid=swg21672354

© www.soinside.com 2019 - 2024. All rights reserved.