Oleg Mikheev
Oleg Mikheev

Reputation: 17444

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.

Upvotes: 6

Views: 7619

Answers (2)

kevin the kitten
kevin the kitten

Reputation: 344

the persistence.xml should exist in a META-INF directory, usually packaged alongside a jar file that contains your entity classes. What I do is I have the entity clases in a seperate project under eclipse, with a META-INF directory that contains the persistence.xml, package this a jar file, and include it in the applications project dependencies (ie. WEB-INF/lib), or, deploy it straight to the app server.

Upvotes: 0

Xavi L&#243;pez
Xavi L&#243;pez

Reputation: 27880

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.

Upvotes: 3

Related Questions