Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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> 
like image 731
user246160 Avatar asked Feb 11 '10 06:02

user246160


People also ask

What is a persistence XML file?

The persistence. xml file is a standard configuration file in JPA. It has to be included in the META-INF directory inside the JAR file that contains the entity beans. The persistence. xml file must define a persistence-unit with a unique name in the current scoped classloader.

Where should persistence xml be located?

If you package the persistence unit as a set of classes in a WAR file, persistence. xml should be located in the WAR file's WEB-INF/classes/META-INF directory.

Which elements belong to persistence unit in persistence xml?

xml file. This file defines a persistence unit named OrderManagement, which uses a JTA-aware data source jdbc/MyOrderDB. The jar-file and class elements specify managed persistence classes: entity classes, embeddable classes, and mapped superclasses.


2 Answers

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.

like image 127
BalusC Avatar answered Sep 16 '22 16:09

BalusC


Right click on jpa project

then

enter image description here

like image 43
H. ELKINA Avatar answered Sep 16 '22 16:09

H. ELKINA