Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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;

//getters and setters
}

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

Hugs, Demetrio

like image 221
Demetrio Avatar asked Jun 01 '11 16:06

Demetrio


3 Answers

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.

like image 196
peater Avatar answered Nov 10 '22 13:11

peater


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>
like image 34
Tom Tresansky Avatar answered Nov 10 '22 11:11

Tom Tresansky


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

like image 4
Alaeddine Avatar answered Nov 10 '22 13:11

Alaeddine