WebLogic 12c (12.2.1.4) with Hibernate 5.4

北慕城南 提交于 2021-01-28 14:53:19

问题


I have an application deployed on WebLogic 12c (12.2.1.4) using Hibernate 5.2.18. Weblogic 12c doc references JPA 2.1 compatibility and Hibernate 5.3+ requires JPA 2.2. Can I prepend the JPA 2.2 API to my startup classpath and use Hibernate 5.3+ or should I stick with Hibernate 5.2 for the time being?


回答1:


Yes, this configuration is possible.

To avoid conflicts with WebLogic built-in JPA capabilities you should do the following:

  1. According to this

In a full Java EE environment, consider obtaining your EntityManagerFactory from JNDI. Alternatively, specify a custom persistenceXmlLocation on your LocalContainerEntityManagerFactoryBean definition (for example, META-INF/my-persistence.xml) and include only a descriptor with that name in your application jar files. Because the Java EE server looks only for default META-INF/persistence.xml files, it ignores such custom persistence units and, hence, avoids conflicts with a Spring-driven JPA setup upfront.

You can use something like this in the spring context config.

<?xml version="1.0" encoding="UTF-8"?>
<beans>
    <!-- ... -->
    <jee:jndi-lookup id="DS" jndi-name="appDS" />
    <bean id="emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
       <property name="persistenceXmlLocation" value="classpath:META-INF/app-persistence.xml" />
       <property name="dataSource" ref="DS" />
    </bean>
    <!-- ... -->
</beans>
  1. According to this

To configure the FilteringClassLoader to specify that a certain package is loaded from an application, add a prefer-application-packages descriptor element to weblogic-application.xml which details the list of packages to be loaded from the application.

You should add the following snippet to your META-INF/weblogic-application.xml

<?xml version="1.0" encoding="UTF-8"?>
<weblogic-application>
    <prefer-application-packages>
        <!-- ... -->
        <package-name>javax.persistence.*</package-name>
    </prefer-application-packages>
</weblogic-application>


来源:https://stackoverflow.com/questions/59906034/weblogic-12c-12-2-1-4-with-hibernate-5-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!