无法使用Spring和JPA解析映射文件

时间:2017-10-09 09:07:09

标签: java spring hibernate jpa persistence.xml

我正在尝试将Spring与JPA集成。我已经定义了一个实体并在persistence.xml下添加了映射文件,但它抛出了异常

Caused by: javax.persistence.PersistenceException: [PersistenceUnit: MyPersistence] Unable to resolve named mapping-file [net.bb.spring.entities.DealDetailsEntity]

我的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="MyPersistence">
<description>AS400 Configuration for BB</description>
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<mapping-file>net.bb.spring.entities.DealDetailsEntity</mapping-file>
<properties>
  <property name="javax.persistence.jdbc.driver" value="com.ibm.as400.access.AS400JDBCDriver" />
  <property name="javax.persistence.jdbc.url" value="jdbc:as400://172.21.100.101/BB" />
  <property name="javax.persistence.jdbc.user" value="ROOT" />
  <property name="javax.persistence.jdbc.password" value="ROOT" />
  <property name="hibernate.show_sql" value="true" />
  <property name="hibernate.hbm2ddl.auto" value="update" />
 </properties>

 </persistence-unit>
 </persistence>

1 个答案:

答案 0 :(得分:1)

关于persistence.xml文件的oracle文档:

  

<mapping-file>元素:指定一个或多个对象关系   映射XML文件(orm.xml文件)。

<mapping-file>指向的是entity java class。这不应传递给<mapping-file>,而应转移到<class>标记。

e.g。

<class>net.bb.spring.entities.DealDetailsEntity</class>