• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

JPA No Persistence provider exception

 
Ranch Hand
Posts: 325
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to use JPA in my servlet to "insert" new record in MySQL table but I am getting an error in my servlet.
Persistence:

Factory:

Pom:

Servlet:

Thanks in advance.
 
Cezar Apulchro
Ranch Hand
Posts: 325
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Error log:
 
Cezar Apulchro
Ranch Hand
Posts: 325
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, the error are ocurring in this line of my servlet:
 
Saloon Keeper
Posts: 6995
164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why is the entity manager factory being closed from the servlet? That should not happen until the application stops.

Right off the bat I notice that you have two conflicting entries for "hibernate.dialect", and a couple of other duplicated properties. See https://www.theserverside.com/blog/Coffee-Talk-Java-News-Stories-and-Opinions/The-right-MySQL-persistencexml-example-file-for-JPA-22-and-Hibernate-5 for further instruction.

The javax.persistence.jdbc.url property isn't correct, so the entire file is invalid anyway.
 
Cezar Apulchro
Ranch Hand
Posts: 325
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Persistence:

Log error:

After to correct persistence the error still the same. Where must be defined META-INF?
Persistence.jpg
[Thumbnail for Persistence.jpg]
 
Tim Moores
Saloon Keeper
Posts: 6995
164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The duplicated properties are all still in there; are they harmful?

Note that the example in Cameron's blog has no "provider" element.

A few more ideas of what can go wrong: https://stackoverflow.com/questions/39410183/hibernate-5-2-2-no-persistence-provider-for-entitymanager
 
Cezar Apulchro
Ranch Hand
Posts: 325
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After to see the example of Cameron and remove duplicate properties the problem still the same.

 
Tim Moores
Saloon Keeper
Posts: 6995
164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the deployed web app, is the persistence.xml file in the correct spot? Where is it?

Does the DB name really have a question mark in it?
 
Cezar Apulchro
Ranch Hand
Posts: 325
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is correct spot to put persistence file? I put him here.
Persistence.jpg
spot of persistence.xml
spot of persistence.xml
 
Cezar Apulchro
Ranch Hand
Posts: 325
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
DB name really wrong I have removed question mark. Sorry.
 
Tim Moores
Saloon Keeper
Posts: 6995
164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Cezar Apulchro wrote:What is correct spot to put persistence file? I put him here.


The correct location is in WEB-INF/classes/META-INF.
 
Cezar Apulchro
Ranch Hand
Posts: 325
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Netbeans when is created a new project the META-INF folder is created inside Web Pages folder I can't understand your comment about location "WEB-INF/classes/META-INF"
 
Tim Moores
Saloon Keeper
Posts: 6995
164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It doesn't matter what NetBeans does. In the deployed application, that's the directory where the file needs to be. If it is not, it will not work. I do see a WEB-INF directory in the image, though.

This is the reason I always advocate to run apps outside of an IDE, because an IDE does some things differently than they work in the real world.

I don't know NetBeans, so I can't advise on how to make it do the right thing. But I do advise to use a standalone server instead for running your application, which uses the directory structure that the servlet spec (and JPA) dictate.
 
Cezar Apulchro
Ranch Hand
Posts: 325
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi I created the persistence.xml file, for that I had to right-click in the project to choose persistence and persistence unit but I can't in the Persistence library field change the default set from EclipseLink (JPA 2.1) to Hibernate. I've tested it like this but I'm getting an error that I show in the error log. I have Hibernate set to library. Can you help me to set hibernate library?
Error log:

Cadastro_Pacientes_JPA01.java:98

Thanks.
 
Tim Moores
Saloon Keeper
Posts: 6995
164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you mean by "set Hibernate library"? You already have a persistence file, why are you creating a new one?

If the IDE is giving you problems, run a standalone server that you can configure any way you want.
 
Cezar Apulchro
Ranch Hand
Posts: 325
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The original problem was to create persistence.xml file then the persistence was created and the problem was solved. Now I will continue to get and solve another problems.
Thanks.
 
I can't beleive you just said that. Now I need to calm down with this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic