类“model.Address”在persistence.xml文件中列出但未映射 [英] Class "model.Address" is listed in the persistence.xml file but not mapped

查看:107
本文介绍了类“model.Address”在persistence.xml文件中列出但未映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个JPA项目。在该Eclipse中,实体类上显示以下错误。


类model.Address列在persistence.xml文件中,但不包括映射


我应该如何在 persistance.xml中映射实体类



这里是 model.Address 实体:



< pre class =lang-java prettyprint-override> 包模型;

import java.io.Serializable;

import javax.persistence。*;

@Entity
public class地址实现Serializable {

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private long id ;
private String city;
private String country;
私人字符串省;
private String postalCode;
private String street;

//为简洁起见省略了Getters / setters。
}

这里是 persistence.xml

 <?xml version =1.0encoding =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_2_0.xsd
version =2.0
>
< provider> org.eclipse.persistance.example.jpa.20.employee.annotations< / provider>

< persistence-unit name =employeetransaction-type =RESOURCE_LOCAL>
< class> model.Employee< / class>
< class> model.Address< / class>

< properties>
< property name =javax.persistence.jdbc.drivervalue =oracle.jdbc.OracleDriver/>
< property name =javax.persistence.jdbc.urlvalue =jdbc:oracle:thin:@localhost:1521:orcl/>
< property name =javax.persistence.jdbc.uservalue =scott/>
< property name =javax.persistence.jdbc.passwordvalue =tiger/>
< / properties>
< / persistence-unit>
< / persistence>


解决方案

这是一个Eclipse的怪癖。当我创建一个禁用JPA库配置的新JPA项目时,我最近刚刚出现了这个问题,但是没有手动配置JPA库 之前我已经通过Eclipse创建了实体新的JPA实体向导。创建实体后,我在项目的<生成路径中配置了JPA库(只需在库中添加目标Java EE服务器运行时),但验证错误仍然存​​在。我可以通过以下方式解决这个问题:


  1. 右键单击 persistence.xml 文件, JPA工具 - > 同步类列表

  2. 或者右键单击验证

  3. 或者关闭/重新打开项目。

这是一贯可重复的。我正在使用Eclipse Indigo SR1。当我在配置JPA库之后创建实体时,不会发生此验证错误。


I have created a JPA project. In that Eclipse displays the following error on the entity class.

Class "model.Address" is listed in the persistence.xml file but not mapped

How am I supposed to map the entity class in persistance.xml?

Here is the model.Address entity:

package model;

import java.io.Serializable;

import javax.persistence.*;

@Entity
public class Address implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    private long id;
    private String city;
    private String country;
    private String province;
    private String postalCode;
    private String street;

    // Getters/setters omitted for brevity.
}

Here is the 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_2_0.xsd"
    version="2.0" 
>
    <provider>org.eclipse.persistance.example.jpa.20.employee.annotations</provider>

    <persistence-unit name="employee" transaction-type="RESOURCE_LOCAL">
        <class>model.Employee</class>
        <class>model.Address</class>

        <properties>
            <property name="javax.persistence.jdbc.driver" value="oracle.jdbc.OracleDriver" />
            <property name="javax.persistence.jdbc.url" value="jdbc:oracle:thin:@localhost:1521:orcl" />
            <property name="javax.persistence.jdbc.user" value="scott" />
            <property name="javax.persistence.jdbc.password" value="tiger" />
        </properties>
    </persistence-unit>
</persistence>

解决方案

This is an Eclipse quirk. I recently had exactly this problem when I created a new JPA project with the JPA library configuration disabled, but didn't manually configure the JPA libraries before I created the entities by the Eclipse New JPA Entity wizard. After creating the entities I configured the JPA libraries in project's Build Path (just by adding target Java EE server runtime in Libraries), but the validation error still remains. I could solve it in at least one of following ways:

  1. Rightclick persistence.xml file, JPA Tools -> Synchronize Class List.
  2. Or, rightclick project, Validate.
  3. Or, close/reopen project.

This is consistently reproducible. I was using Eclipse Indigo SR1. When I create the entities after configuring the JPA libraries, this validation error doesn't occur.

这篇关于类“model.Address”在persistence.xml文件中列出但未映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆