类“部门”已映射,但不包含在任何持久性单元中

发布于 11-13 10:52 字数 704 浏览 4 评论 0原文

我收到此错误,但不知道原因:“部门”类已映射,但不包含在任何持久性单元中。

我有两个项目。 一是在我的 persistence.xml 中,标记之间只有两行:

<persistence-unit name="UserJPA">
</persistence-unit>

我的类是:

package br.com.jm.user;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;;

@Entity
@Table(name = "DEPARTMENT")
public class Department implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    private Long id;
    private String name;

//getters and setters
}

我正在使用 EclipseLink2.1.2。事实上,如果它能让事情变得更容易的话,我可以删除它。

拥抱, 德梅特里奥

I am getting this error and I have no idea the reason: Class "Department" is mapped, but is not included in any persistence unit.

I have two project.
One is In my persistence.xml, between tag, there is only two lines:

<persistence-unit name="UserJPA">
</persistence-unit>

My class is:

package br.com.jm.user;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;;

@Entity
@Table(name = "DEPARTMENT")
public class Department implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    private Long id;
    private String name;

//getters and setters
}

I am using EclipseLink2.1.2. Actually I can remove this if it makes the things easier.

Hugs,
Demetrio

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

自控2024-11-20 10:52:00

对于在 Eclipse 或 RAD 中搜索“类 xxxx 已映射,但未包含在任何持久性单元中”错误时发现此老问题的任何人,请参阅 这个问题和答案有适合我的解决方案:

  1. 右键单击项目并选择属性。
  2. 选择 JPA
  3. 选择单选按钮“自动发现带注释的类”
  4. 确定并等待项目完成构建。

这些步骤对我有用。

For anyone who finds this old question when searching for the "Class xxxx is mapped, but is not included in any persistence unit" error in Eclipse or RAD, a comment on this question and answer has the solution that worked for me:

  1. Right-click on the project and choose properties.
  2. Select JPA
  3. Select the radio button "Discover annotated classes automatically"
  4. OK and wait for the project to finish building.

These steps worked for me.

暮凉2024-11-20 10:52:00

您需要在 persistence.xml 文件中指定持久单元中包含哪些类,如下所示:

<persistence-unit name="UserJPA">
    <class>br.com.jm.user.Department</class>
</persistence-unit>

You need to specify what classes are included in the persistence unit in the persistence.xml file, like this:

<persistence-unit name="UserJPA">
    <class>br.com.jm.user.Department</class>
</persistence-unit>
谎言2024-11-20 10:52:00

右键单击项目资源管理器中的 persistance.xml 文件

,然后单击同步类列表

它将自动生成您的类标签

在此处输入图像描述

Right click on persistance.xml file in your project explorer

then click Synchronize Class List

it will generate your Class tags automatically

enter image description here

萌酱2024-11-20 10:52:00

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>..</persistence-unit>
 </persistence>

The persistence.xml should have:

<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>..</persistence-unit>
 </persistence>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文