EclipseLink - not Entity as target in relationship attribute

I am using Netbeans IDE 8.0.2 and eclipselink 2.5.2. This is the exception thrown below when opening a connection, the problem is it doesn't happen every time. The entity described in the exception "Department" exactly follows the pattern of other classes, that our system already contains approximately 500 entity classes, and this exception occurs only in new classes. This object was generated by this Netbeans Database Entities option and added to XML persistense ...

Caused by: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.EntityManagerSetupException Exception Description: Failed to preconfigure PersistencePUnit. [Totem Inner Exception: Exception [EclipseLink-7250] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.ValidationException Exception Description: [class entidade.Item] uses non-entity [class entidade.Departamento ] as the target object in the [field departmentamento] relationship attribute.

Entity Departamento

@Entity
@Table(name = "departamento")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "Departamento.findAll", query = "SELECT d FROM Departamento d"),
@NamedQuery(name = "Departamento.findById", query = "SELECT d FROM Departamento d WHERE   d.departamentoPK.id = :id"),
@NamedQuery(name = "Departamento.findByIdEmpresa", query = "SELECT d FROM Departamento d WHERE d.departamentoPK.idEmpresa = :idEmpresa"),
@NamedQuery(name = "Departamento.findByDescricao", query = "SELECT d FROM Departamento d WHERE d.descricao = :descricao"),
@NamedQuery(name = "Departamento.findByLixo", query = "SELECT d FROM Departamento d WHERE d.lixo = :lixo"),
@NamedQuery(name = "Departamento.findByIp", query = "SELECT d FROM Departamento d WHERE d.ip = :ip")})
public class Departamento implements Serializable {

private static final long serialVersionUID = 1L;
@EmbeddedId
protected DepartamentoPK departamentoPK;
@Basic(optional = false)
@Column(name = "descricao")
private String descricao;
...
Getters() and Setters()

      

Object element

@Entity
@Table(name = "item")
public class Item implements Serializable {

@EmbeddedId
protected ItemPK itemPK;
@JoinColumns({
    @JoinColumn(name = "departamento_id", referencedColumnName = "id"),
    @JoinColumn(name = "departamento_id_empresa", referencedColumnName = "id_empresa")})
@ManyToOne(optional = true)
private Departamento departamento;
...
Getters() and Setters()

      

persistence.xml

<persistence-unit name="totemPU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>entidade.Departamento</class>
<class>entidade.item</class>
... More classes ...
<properties>
  <property name="javax.persistence.jdbc.url" value="jdbc:mysql://xxx"/>
  <property name="javax.persistence.jdbc.password" value="xxx"/>
  <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
  <property name="javax.persistence.jdbc.user" value="xxx"/>
  <property name="javax.persistence.jdbc.autoReconnect" value="true"/>
  <property name="eclipselink.logging.session" value="false"/>
  <property name="eclipselink.logging.level" value="OFF"/>
  <property name="eclipselink.weaving" value="static"/>
  <property name="eclipselink.query-results-cache" value="false"/>
</properties>

      

There are three more persistence units in the same persistence.xml file.

+3


source to share


1 answer


I usually see this error when I forget to add a class to my persistence.xml that is trying to use another object. Make sure the persistence item name you pass to create the EntityManagerFactory is what you want (totemPU). It seems like it might be using a save unit that includes entidade.item but not entidade.Departamento.



+7


source







All Articles