简体   繁体   中英

Overloading the provider in persistence.xml results in ClassNotFoundException

I'm attempting to use a custom provider in persistence.xml (actually, just creating a thin facade in front of the Hibernate Provider in order to capture audit data).

I've changed the persistence.xml to look like (based on a similar stackoverflow post here)

The relevant portion of the file now looks like

<persistence-unit name="oauth2server-ds">
  <!-- <provider>org.hibernate.ejb.HibernatePersistence</provider> -->
  <provider>psu.edu.javaee.audit.producer.MyHibernatePersistenceProvider</provider>
  <jta-data-source>java:jboss/datasources/oauth2server-ds</jta-data-source>

I've verified that the class psu.edu.javaee.audit.producer.MyHibernatePersistenceProvider is in the .war I'm deploying, but I still get a

Caused by: javax.persistence.PersistenceException: JBAS011466: PersistenceProvider 'psu.edu.javaee.audit.producer.MyHibernatePersistenceProvider' not found

Is there anything additional I need to do to make this class visible on the classpath? I'm on wildfly-8.2.0-Final if that has any relevance.

The answer turned out to be adding a services directory in the META-INF directory and inside the services directory add a file called javax.persistence.spi.PersistenceProvider that contains the fully qualified name of the the replacement persistence provider. Thanks to Alex H. for the help.

So, META-INF/services/javax.persistence.spi.PersistenceProvider with the fully qualified name of the replacement provider.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM