I am using the Netbeans IDE 8.0.2 and eclipselink 2.5.2. This occurring exception below when opening a connection, the problem is that this does not happen every time. The entity described in exception "Departmento" exactly follows the pattern of the other classes being that our system already contain approximately 500 entity classes and only in the new classes are taking place this exception. This entity was generated by that option "Entity Classes from Database" of Netbeans and added to the persistense XML ...
Caused by: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.EntityManagerSetupException Exception Description: Predeployment of PersistenceUnit [totemPU] failed. Internal Exception: Exception [EclipseLink-7250] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.ValidationException Exception Description: [class entidade.Item] uses a non-entity [class entidade.Departamento] as target entity in the relationship attribute [field departamento].
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()
Entity Item
@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>
In the same persistence.xml there are more three persistences unit.
I usually see this error when I forget to add a class in my persistence.xml that another entity tries to use. Make sure that the persistence-unit name you are passing in to create the EntityManagerFactory is the one you want (totemPU). It seems like it maybe using a persistence-unit that includes entidade.item but not entidade.Departamento.