Configure Hibernate to use renamed persistence.xml

We must rename persistence.xml to trick WebSphere 7 into not using its built-in OpenJPA.

This is pretty easy to do when you use Spring, you just instruct its factory entity manager to use another place for persistence.xml:

<property name="persistenceXmlLocation" value="META-INF/persistence-xxx.xml"/> 

But now we want to use a simple Hibernate / JPA without Spring and could not find a way to specify an alternative location for persistence.xml.

The JPA2 specification says nothing about this ...

Any clues? Is it possible to tell Hibernate to use the renamed persistence.xml?

======

It seems that it IS IMPOSSIBLE to force Hibernate to read the renamed persistence.xml file. And not necessarily in my case.

+6
source share
2 answers

As far as I know, changing the location of the persistence.xml file is not possible.

Also take a look at this document: Alternative JPA providers in WebSphere Application Server , it looks like you should use Hibernate as a JPA provider by specifying it in the persistence.xml file and entering the necessary banks in your application.

Make sure your persistence.xml points to Hibernate as a JPA provider:

 <persistence> <persistence-unit name="myapp"> <provider>org.hibernate.ejb.HibernatePersistence</provider> 

You should also be able to achieve this by creating a shared library and using it to configure WebSphere to use an alternative continuity provider. Here you can find how to do this: Configure the Java Persistence API Provider (JPA)

EDIT Given the information in the comments in this answer, it seems the problem can be solved by adding these properties to persistence.xml , as indicated in this post Problem creating WebSphere EntityManagerFactory :

 <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.WebSphereExtendedJTATransactionLookup" /> <property name="hibernate.transaction.factory_class" value="org.hibernate.transaction.CMTTransactionFactory" /> 

The same information is also provided in alternative JPA providers in the WebSphere Application Server document.

+3
source

persistence.xml must exist in the META-INF directory, usually packaged with a jar file that contains entity classes. What I do is that I have clusters of objects in a separate project under eclipse, with the META-INF directory, which contains the persistence.xml file, packs this jar file and includes it depending on application projects (i.e. WEB-INF / lib) or deploy it directly to the application server.

0
source

Source: https://habr.com/ru/post/901193/


All Articles