EclipseLink-非Entity作为关系属性中的目标实体 [英] EclipseLink - non Entity as target entity in the relationship attribute

查看:170
本文介绍了EclipseLink-非Entity作为关系属性中的目标实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Netbeans IDE 8.0.2和eclipselink 2.5.2. 下面在打开连接时会发生这种异常,问题是这种情况不会每次都发生. 异常部门"中描述的实体完全遵循其他类的模式,因为我们的系统已经包含大约500个实体类,并且仅在新类中才发生此异常. 该实体是由Netbeans的选项数据库中的实体类"生成的,并已添加到persistense XML中.

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 ...

原因:javax.persistence.PersistenceException:异常[EclipseLink-28018](Eclipse Persistence Services-2.5.2.v20140319-9ad6abd):org.eclipse.persistence.exceptions.EntityManagerSetupException 异常描述:PersistenceUnit [totemPU]的预部署失败. 内部异常:异常[EclipseLink-7250](Eclipse Persistence Services-2.5.2.v20140319-9ad6abd):org.eclipse.persistence.exceptions.ValidationException 异常描述:[entidade.Item类]使用非实体[entidade.Departamento类]作为关系属性[field departamento]中的目标实体.

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
@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
@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.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>

在相同的persistence.xml中,存在三个以上的持久性单元.

In the same persistence.xml there are more three persistences unit.

推荐答案

当我忘记在我的persistence.xml中添加另一个实体尝试使用的类时,通常会看到此错误.确保传递给您用于创建EntityManagerFactory的持久性单元名称是您想要的名称(totemPU).似乎它可能使用包含entidade.item但不包含entidade.Departamento的持久性单元.

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.

这篇关于EclipseLink-非Entity作为关系属性中的目标实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆