问题
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:
- According to this
In a full Java EE environment, consider obtaining your
EntityManagerFactory
from JNDI. Alternatively, specify a custompersistenceXmlLocation
on yourLocalContainerEntityManagerFactoryBean
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 defaultMETA-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>
- According to this
To configure the
FilteringClassLoader
to specify that a certain package is loaded from an application, add aprefer-application-packages
descriptor element toweblogic-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