Spring Data - JPA:无法提取ResultSet

时间:2017-10-23 15:59:43

标签: java hibernate spring-data

HY,

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

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

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

Udsaconnex:

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

    @Id
    private long idconnex;

    private String clesecrete;

    private Timestamp dateconnex;

    private String mel;

    private int tel;

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

    //Getter and setter
}

Udsadonnees:

@Entity
@NamedQuery(name="Udsadonnees.findAll", query="SELECT u FROM Udsadonnees u")
@Table(name="udsadonnees")
public class Udsadonnees 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 Udsaconnex
    @ManyToOne
    private Udsaconnex udsaconnex;

    public Udsadonnees() {
    }

    //Getter and Setter

}

我的CrudRepository:

public interface UDADRESSRepository extends CrudRepository<Udadress, Integer> {
}

数据库:

enter image description here

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

我有人有个主意......

2 个答案:

答案 0 :(得分:0)

您无法将enitity的双向关系转换为JSON。你得到一个无限循环尝试添加@JsonIgnore来打破你的双向关联循环

  @ManyToOne
  @JsonIgnore
  private Udsaconnex udsaconnex;

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

答案 1 :(得分:-1)

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

在父类中:

<ng-container *ngFor="let item of logList">
    <div  class="list-cell" (click)="onRowClicked(item)">
        <mat-grid-tile> {{item.name}} </mat-grid-tile>
        <mat-grid-tile> {{item.time}} </mat-grid-tile>
        <mat-grid-tile> {{item.size}} </mat-grid-tile>
    </div>
</ng-container>

在子类中:

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

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