persistence.xml应该在哪里?

时间:2014-11-24 20:42:00

标签: java hibernate

我正在试图弄清楚为什么我的Java程序会返回“EntityManager名称WroProjectPU没有持久性提供程序” 我认为它正在发生,因为Java无法找到persistence.xml文件。

我尝试使用不同的配置,但没有人工作。 目前,我的程序结构如下:

enter image description here

其中选择的Main.java文件是文件,我有

EntityManagerFactory emf =  
        Persistence.createEntityManagerFactory("WroProjectPU");  

主文件夹WroProject位于此绝对位置:

C:\Users\Szymon\workspace\WroProject

你能告诉我应该把我的persistence.xml文件放在哪里吗?请完整的绝对路径。

提前致谢!

编辑后: 我的persistence.xml看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
  <persistence-unit name="WroProjectPU" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>db.User</class>
    <class>db.Session</class>
    <class>db.Email</class>
    <class>db.File</class>
    <class>db.FilePermission</class>
<properties>
  <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/wroproject"/>
  <property name="javax.persistence.jdbc.password" value="postgres"/>
  <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
  <property name="javax.persistence.jdbc.user" value="postgres"/>
</properties>

问题:

lis 24, 2014 9:30:31 PM org.hibernate.ejb.HibernatePersistence logDeprecation
WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
lis 24, 2014 9:30:31 PM org.hibernate.ejb.HibernatePersistence logDeprecation
WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
lis 24, 2014 9:30:31 PM org.hibernate.ejb.HibernatePersistence logDeprecation
WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named WroProjectPU
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:61)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
    at wroproject.Main.main(Main.java:18)
Java Result: 1

0 个答案:

没有答案