提取结果集失败

问题描述 投票:0回答:2

我的 Spring Data/JPA 项目出现此错误:

SQL Error: -206, SQLState: 42703 
DB2 SQL Error: SQLCODE=-206, SQLSTATE=42703, SQLERRMC=MYDONNEE0_.MYCONNEX_IDCON, DRIVER=4.19.26 
SQL Error: -727, SQLState: 56098 
DB2 SQL Error: SQLCODE=-727, SQLSTATE=56098, SQLERRMC=2;-206;42703;MYDONNEE0_.MYCONNEX_IDCON, DRIVER=4.19.26 
SQL Error: -727, SQLState: 56098 
DB2 SQL Error: SQLCODE=-727, SQLSTATE=56098, SQLERRMC=2;-206;42703;MYDONNEE0_.MYCONNEX_IDCON, DRIVER=4.19.26 
Enter: my.package.test.web.rest.errors.ExceptionTranslator.processRuntimeException() with argument[s] = [org.springframework.http.converter.HttpMessageNotWritableException: Could not write content: could not extract ResultSet (through reference chain: my.package.test.repository.entity.MYconnex["MYdonnees"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: could not extract ResultSet (through reference chain: my.package.test.repository.entity.MYconnex["MYdonnees"])] 
Exit: my.package.test.web.rest.errors.ExceptionTranslator.processRuntimeException() with result = <500 Internal Server Error,my.package.test.web.rest.errors.ErrorDTO@70b511c1,{}> 

我搜索,但我没有发现我的实体有问题。

我的连接:

@Entity
@NamedQuery(name="MYconnex.findAll", query="SELECT u FROM MYconnex u")
public class MYconnex implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    private long IDCON;

    private String key;

    private Timestamp dateconnex;

    private String mel;

    private int tel;

    //bi-directional many-to-one association to MYdonnees
    @OneToMany(mappedBy="MYconnex")
    private List<MYdonnees> MYdonnees;

    //Getter and setter
}

我的女儿:

@Entity
@NamedQuery(name="MYdonnees.findAll", query="SELECT u FROM MYdonnees u")
@Table(name="MYdonnees")
public class MYdonnees implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    private long idata;

    @Lob
    @Column(name="\"DATA\"")
    private String data;

    //bi-directional many-to-one association to MYconnex
    @ManyToOne
    private MYconnex MYconnex;

    public MYdonnees() {
    }

    //Getter and Setter

}

我的 Crud 存储库:

public interface ADRESSRepository extends CrudRepository<ADRESS, Integer> {
}

数据库:

我认为问题来自实体,但我找不到这个问题。

java hibernate spring-data
2个回答
0
投票

您无法将实体的双向关系转换为 JSON。您会遇到无限循环尝试添加 @JsonIgnore 来打破双向关联上的循环

  @ManyToOne
  @JsonIgnore
  private Udsaconnex udsaconnex;

@jsonsetter  
public void setUdsaconnex(Udsaconnex udsaconnex){
     this.udsaconnex = udsaconnex;
}

-2
投票

我遇到了同样的问题,这对我有用:

在父类中:

@JsonIgnore // to break endless loop in bi-directional association
public List<Udsaconnex> getUdsadonnees() {
    return udsadonnees;
}

儿童班:

 @ManyToOne
 @JoinColumn(name = "idconnex") // You must specify the join column.
 private Udsaconnex udsaconnex;

这两项更改将解决您的问题。

© www.soinside.com 2019 - 2024. All rights reserved.