jpa error uses a non-entity [class ch.printsoft.mailhouse.usermgr.entity.Department] as target entity in the relationship attribute

Miguel Iglesias picture Miguel Iglesias · Dec 2, 2011 · Viewed 25.6k times · Source

I try to persist my Department and Mandator classes to hsqhldb but it gives this error.

Exception Description: [class ch.printsoft.mailhouse.usermgr.entity.Mandator] uses a non-entity [class ch.printsoft.mailhouse.usermgr.entity.Department] as target entity in the relationship attribute [field departments].
at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(PersistenceUnitLoadingException.java:126)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:115)
at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)

These are the classes that I try to persist to my database. I really don't know what the problem is.

@Entity
public class Mandator {
  @Id
  @GeneratedValue
  private Integer id;
  private String mandatorId;
  @OneToMany(mappedBy = "mandator")
  private List<MandatorUser> mandatorUsers;
  @OneToMany(mappedBy = "mandator")
  private List<SLAFamilyGroup> slaFamilyGroups;
  @OneToMany(mappedBy = "mandator")
  private List<Group> groups;
  @OneToMany(mappedBy = "mandator")
  private List<Department> departments;
  @OneToMany(mappedBy = "mandator")
  private List<CostUnit> costUnits;



@Entity
  public class Department {
  @Id
  @GeneratedValue
  private Integer id;
  private String name;
  private String responsiblePerson;
  private String location;

  @ManyToOne(optional = false)
  private Mandator mandator;
  @ManyToMany
  private List<DocumentUser> documentUsers;

I've really tried every thing but it didn't work.

Answer

James picture James · Dec 5, 2011

Ensure you have both classes listed in your persistence.xml, and the both classes are on the classpath.

Please include your persistence.xml.