0

In this question, you can see that I have an issue that I resolved it only changing hibernate version. It seems to me that I would be able to overcome it if I can override some methods from HibernatePersistenceProvider class. I did created my own class that extends it, but if I specify it as provider in the <provider> tag from persistence.xml class, I get a javax.persistence.PersistenceException: No Persistence provider for EntityManager named X exception.

Can anyone guide me on how should I override the default hibernate provider class with my own?

Community
  • 1
  • 1
artaxerxe
  • 6,281
  • 21
  • 68
  • 106
  • I really to not understand why you extended Hibernate's pers. provider. You said you solved your problem by simply changing the version, but why extending? – V G Mar 05 '14 at 10:14
  • @AndreiI Yes. But I think about using version 4.3.1 with my own provider. – artaxerxe Mar 05 '14 at 10:16
  • Why are you thinking that? Why making things more complicated? What is your real problem/are trying to achieve? – V G Mar 05 '14 at 10:17
  • @AndreiI I put it in my question. It's a kind of trial: I would like to provide a custom class as provider for Hibernate. I didn't get it if I only override the original one and specify it as provider. What's not clear? – artaxerxe Mar 05 '14 at 10:20
  • OK, I see now. In your answer you told that you simply replaced the version (without extending it). I posted there another answer. Please try it. – V G Mar 05 '14 at 10:24

1 Answers1

2

If you want to create a JPA persistence provider class and have the Persistence.createEntityManagerFactory(props) be able to use it, you need to register your provider class in a way the Persistence class can find it. You need a META-INF\services\javax.persistence.spi.PersistenceProvider file to list your PersistenceProvider implementation so the Persistence class can find all providers to load persistence.xml files.

For more details, see chapter "9.2 Bootstrapping in Java SE Environments" of the JPA Specification, located here.

artaxerxe
  • 6,281
  • 21
  • 68
  • 106
Chris
  • 20,138
  • 2
  • 29
  • 43