"No persistence unit with name 'product' found"

28,263

Solution 1

You need a META-INF/persistence.xml, with <persistence-unit name="product">. See here

(I usually put it in WEB-INF/classes/META-INF. As noted in the comments, with maven you can place it in src/main/resources/META-INF)

Solution 2

this is a example of file persistence.xml

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
         version="2.0">
<persistence-unit name="poduct"  transaction-type="RESOURCE_LOCAL">
</persistence-unit>
</persistence>

create this file inside "src/main/resources/META-INF" if you use Maven project.

Solution 3

I run onto the same problem and had to manually edit the Web Deployment Assembly Configuration so as to instruct /META-INF/persistence.xml to be deployed under WEB-INF/classes/ (the red box in the attached img was manually edited)

Solution 4

i have the same problem. But when you use the ide(for example eclipse) and configure your server in the ide. When you asosiate the piece and restart the server always have the same error because detected the persistence unit is used, you need delete that part of the server and deploy to the oldway. Enter to the console and install the peace of you project and works!!

And the other is when you check the diagnostic in wls you need said who user is the owner of the jdbc, only select and check (for example, AdminServer) and save and check again!!

:D

Share:
28,263
Admin
Author by

Admin

Updated on July 23, 2022

Comments

  • Admin
    Admin almost 2 years

    I recently completed this tutorial: "http://static.springsource.org/docs/Spring-MVC-step-by-step/", but now I want it to work with Hibernate and annotations. I know I'm close but I've hit a roadblock and I can't figure it out. I've posted my code on the Spring forums here. I would greatly appreciate ANY help. Thanks

    I'm trying to incorporate annotations and hibernate into it, but I've run into a problem and I can't figure it out. I keep getting errors of "No persistence unit with name 'product' found". ANY help would be greatly appreciated.

  • Ralph
    Ralph over 13 years
    Sean Patrick Floyd is right: at least the persistence.xml have to be located at \WEB-INF\classes\META-INF\persistence.xml (for an standard web application) -- In normal case you reach this goal if you put the persistence.xml in the META-INF directory of you java sources directory. (If you use maven than put it in src/main/resources/META-INF/persistence.xml.)
  • Bozho
    Bozho over 13 years
    sorry, corrected. I usually put it in WEB-INF/classes/META-INF though
  • Admin
    Admin over 13 years
    I already have persistance.xml... when I created it, I also created the META-INF folder. The WEB-INF folder was created when I went through the tutorial. Thanks
  • Bozho
    Bozho over 13 years
    @type7 - and..? The problem should be resolved if the xml is in the correct location. Show it to us
  • Admin
    Admin over 13 years
    ahhh... putting META-INF into the classes folder worked. Thanks!
  • vach
    vach about 10 years
    @Bozho is there a way to use custom location of persistence.xml? (i'd like to place it right in resources/ folder and still have it discovered by spring)
  • blm
    blm over 8 years
    This isn't very clear to me. Could you provide specific steps? Also, what differentiates your answer from the other answers already provided? Maybe this is more appropriate as a comment?
  • OO7
    OO7 over 8 years
    Thanks for sharing this with us. added META-INF in classes will solve my issue. +1