gpt4 book ai didi

java - MappedBy 引用未知目标实体属性两次?

转载 作者:行者123 更新时间:2023-12-02 05:02:38 27 4
gpt4 key购买 nike

我有一个查询,我碰巧有一个名为“SGOrdCompra”的表,将他与“SGPersona”链接了两次,表如下:

Sgordcompra.java

@Entity
@Table(name = "`SGOrdCompra`", schema = "`public`")
public class Sgordcompra implements java.io.Serializable {

.....
private Sgpersona sgpersonaByIcodSolicitante;
private Sgpersona sgpersonaByIcodComprador;


@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "`iCodSolicitante`", nullable = false)
public Sgpersona getSgpersonaByIcodSolicitante() {
return this.sgpersonaByIcodSolicitante;
}

public void setSgpersonaByIcodSolicitante(
Sgpersona sgpersonaByIcodSolicitante) {
this.sgpersonaByIcodSolicitante = sgpersonaByIcodSolicitante;
}

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "`iCodComprador`", nullable = false)
public Sgpersona getSgpersonaByIcodComprador() {
return this.sgpersonaByIcodComprador;
}

public void setSgpersonaByIcodComprador(Sgpersona sgpersonaByIcodComprador) {
this.sgpersonaByIcodComprador = sgpersonaByIcodComprador;
}

}

Sgpersona.java

@Entity
@Table(name = "`SGPersona`", schema = "`public`")
public class Sgpersona implements java.io.Serializable {

private static final long serialVersionUID = 1L;
private int icodPersona;
private Set<Sgrencajchica> sgrencajchicas = new HashSet<Sgrencajchica>(0);
....
private Set<Sgordcompra> sgordcomprasForIcodComprador = new HashSet<Sgordcompra>(0);
private Set<Sgordcompra> sgordcomprasForIcodSolicitante = new HashSet<Sgordcompra>(0);

@OneToMany(fetch = FetchType.LAZY, mappedBy = "sgpersona")
public Set<Sgrencajchica> getSgrencajchicas() {
return this.sgrencajchicas;
}

public void setSgrencajchicas(Set<Sgrencajchica> sgrencajchicas) {
this.sgrencajchicas = sgrencajchicas;
}

.......

@OneToMany(fetch = FetchType.LAZY, mappedBy = "sgpersona")
public Set<Sgordcompra> getSgordcomprasForIcodComprador() {
return this.sgordcomprasForIcodComprador;
}

public void setSgordcomprasForIcodComprador(
Set<Sgordcompra> sgordcomprasForIcodComprador) {
this.sgordcomprasForIcodComprador = sgordcomprasForIcodComprador;
}



@OneToMany(fetch = FetchType.LAZY, mappedBy = "sgpersona")
public Set<Sgordcompra> getSgordcomprasForIcodSolicitante() {
return this.sgordcomprasForIcodSolicitante;
}

public void setSgordcomprasForIcodSolicitante(
Set<Sgordcompra> sgordcomprasForIcodSolicitante) {
this.sgordcomprasForIcodSolicitante = sgordcomprasForIcodSolicitante;
}

}

我收到此错误:

ERROR: org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'iGenericDao': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory org.sgkyros.common.dao.impl.GenericDaoImpl.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/application-context.xml]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: org.sgkyros.common.entity.Sgordcompra.sgpersona in org.sgkyros.common.entity.Sgpersona.sgordcomprasForIcodComprador

但是如果我评论与“Sgpersona”类相关的代码行,测试它通常对我有用,应该是......?

private Set<Sgordcompra> sgordcomprasForIcodComprador = new HashSet<Sgordcompra>(0);    
private Set<Sgordcompra> sgordcomprasForIcodSolicitante = new HashSet<Sgordcompra>(0);

最佳答案

mappedBy 属性试图引用类“Sgordcompra”中的无效属性“sgpersona”。 OneToMany 映射应按如下方式完成:

@OneToMany(fetch = FetchType.LAZY, mappedBy = "sgpersonaByIcodComprador")
public Set<Sgordcompra> getSgordcomprasForIcodComprador() {
return this.sgordcomprasForIcodComprador;
}

@OneToMany(fetch = FetchType.LAZY, mappedBy = "sgpersonaByIcodSolicitante")
public Set<Sgordcompra> getSgordcomprasForIcodSolicitante() {
return this.sgordcomprasForIcodSolicitante;
}

关于java - MappedBy 引用未知目标实体属性两次?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28103164/

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