类“model.Address”在persistence.xml文件中列出但未映射

编程入门 行业动态 更新时间:2024-10-23 19:34:29
本文介绍了类“model.Address”在persistence.xml文件中列出但未映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我已经创建了一个JPA项目。在该Eclipse中,实体类上显示以下错误。

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

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

这里是 model.Address 实体:

包模型; 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 =java.sun/xml/ns/persistence xmlns:xsi =www.w3/2001 / XMLSchema-instance xsi:schemaLocation =java.sun/xml/ns/persistence java.sun/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服务器运行时),但验证错误仍然存​​在。我可以通过以下方式解决这个问题:

  • 右键单击 persistence.xml 文件, JPA工具 - > 同步类列表。
  • 或者右键单击验证。
  • 或者关闭/重新打开项目。
  • 这是一贯可重复的。我正在使用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="java.sun/xml/ns/persistence" xmlns:xsi="www.w3/2001/XMLSchema-instance" xsi:schemaLocation="java.sun/xml/ns/persistence java.sun/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:

  • Rightclick persistence.xml file, JPA Tools -> Synchronize Class List.
  • Or, rightclick project, Validate.
  • 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文件中列出但未映射

    本文发布于:2023-10-25 14:10:23,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1527187.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:但未   文件   Address   model   xml

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!