求助:eclipse报错This mapped class is not specified in persistence unit " "

selena_c 2010-08-17 10:48:34
我在学习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>


在线等啊~~
谢谢啦先~
...全文
150 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
tarbitrary 2012-03-21
  • 打赏
  • 举报
回复
在persistence.xml加上一句<persistence-unit name="tarbitrary" transaction-type="RESOURCE_LOCAL">
<class>包名.Person</class>
</persistence-unit>
foxegg 2010-11-11
  • 打赏
  • 举报
回复
学习一下。谢谢!
Joy 2010-08-17
  • 打赏
  • 举报
回复
src是放源码的,放里面需要用得到类路径
selena_c 2010-08-17
  • 打赏
  • 举报
回复
又看了看我的项目结构,发现persistence.xml被我放在了src目录下,把它单独拿出来,就不报这个错误了。
根本原因不知道为什么,有人能解答吗?

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧