我在学习JPA,照着视频教程做的。但是在注释@Entity时,这一行报错This mapped class is not specified in persistence unit "test_cailq"持久化类Person的代码如下:package cn.itcast.bean;import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;@Entity
public class Person {

private Integer id;
private String name;

public Person(){}

public Person(String name) {
this.name = name;
}
@Id @GeneratedValue(strategy = GenerationType.AUTO)
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
配置文件persistence.xml代码如下:<?xml version="1.0" encoding="UTF-8"?>
<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_1_0.xsd" version="1.0">
  <persistence-unit name="test_cailq" transaction-type="RESOURCE_LOCAL">
   <provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
         <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
         <property name="hibernate.connection.url" value="jdbc:mysql://10.1.29.106:3306/test_cailq"/>
 <property name="hibernate.connection.username" value="root"/>
         <property name="hibernate.connection.password" value=""/>
         <property name="hibernate.max_fetch_depth" value="3"/>
         <property name="hibernate.hbm2ddl.auto" value="update"/>
     <property name="hibernate.jdbc.fetch_size" value="18"/>
     <property name="hibernate.jdbc.batch_size" value="10"/>
     <property name="hibernate.show_sql" value="false"/>
     <property name="hibernate.format_sql" value="false"/> 
      </properties>
  </persistence-unit>
</persistence>
在线等啊~~
谢谢啦先~

解决方案 »

  1.   

    又看了看我的项目结构,发现persistence.xml被我放在了src目录下,把它单独拿出来,就不报这个错误了。
    根本原因不知道为什么,有人能解答吗?
      

  2.   

    src是放源码的,放里面需要用得到类路径
      

  3.   

    在persistence.xml加上一句<persistence-unit name="tarbitrary" transaction-type="RESOURCE_LOCAL">
       <class>包名.Person</class> 
    </persistence-unit>