Class "Department" is mapped, but is not included in any persistence unit
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;
//gette开发者_如何学运维rs and setters
}
I am using EclipseLink2.1.2. Actually I can remove this if it makes the things easier.
Hugs, Demetrio
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:
- Right-click on the project and choose properties.
- Select JPA
- Select the radio button "Discover annotated classes automatically"
- OK and wait for the project to finish building.
These steps worked for me.
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>
Right click on persistance.xml file in your project explorer
then click Synchronize Class List
it will generate your Class tags automatically
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>
精彩评论