Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

configure Hibernate to use a renamed persistence.xml

We have to rename persistence.xml to fool WebSphere 7 not to use its built-in OpenJPA.

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

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

But now we want to use plain Hibernate/JPA without Spring, and couldn't find any way to specify the alternate persistence.xml location.

JPA2 spec doesn't say anything about it...

Any clues? Is it possible to instruct Hibernate to use a renamed persistence.xml?

======

It appears that it is NOT POSSIBLE to make Hibernate read a renamed persistence.xml file. And not necessary in my case.

like image 699
Oleg Mikheev Avatar asked Nov 10 '11 09:11

Oleg Mikheev


People also ask

What is correct location for persistence xml file?

The persistence. xml file is a standard configuration file in JPA. It has to be included in the META-INF directory inside the JAR file that contains the entity beans.

Can we have multiple persistence xml?

xml files. Have multiple persistence units in one persistence.


1 Answers

As far as I know, it's not possible to change the location of the persistence.xml file.

Also take a look at this document: Alternate JPA Providers in WebSphere Application Server, it seems like you should be able to use Hibernate as JPA provider by specifying it in the persistence.xml file, and embedding the required jars in your application.

Make sure your persistence.xml is specifying Hibernate as 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 persistence provider. Here you can find how to do it: Configuring the Java Persistence API (JPA) default persistence provider

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

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

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

This same information is also provided in the Alternate JPA Providers in WebSphere Application Server document.

like image 71
Xavi López Avatar answered Sep 30 '22 09:09

Xavi López