gpt4 book ai didi

jpa - EclipseLink - 非实体作为关系属性中的目标实体

转载 作者:行者123 更新时间:2023-12-03 22:33:23 24 4
gpt4 key购买 nike

我使用的是 Netbeans IDE 8.0.2 和 eclipselink 2.5.2。
打开连接时发生的这种异常如下,问题是这不会每次都发生。
异常“Departmento”中描述的实体完全遵循其他类的模式,即我们的系统已经包含大约 500 个实体类,并且只有在新类中才会发生这种异常。
该实体是由 Netbeans 的“数据库中的实体类”选项生成的,并添加到持久性 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
@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-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 中有更多的三个持久性单元。

最佳答案

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

关于jpa - EclipseLink - 非实体作为关系属性中的目标实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27422993/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com