我尝试从两个表(Statement、AppCurContract)进行查询,但收到很多重复记录。即使我只从 Statement 进行查询,我也会收到相同的结果。当我将 appCurContracts 字段添加到 Statement bean 时,它就开始了。
我在这里发现了同样的问题Spring Data JPA 查询返回重复行而不是实际数据,为什么?
但是我在两个表中都有唯一的键。我究竟做错了什么?
这是我的代码
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.persistence.*;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@Entity
@Table
@Data
@EqualsAndHashCode(exclude = "appCurContracts")
public class Statement {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String numStatement;
@Column(updatable = false)
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime dateTimeSubmStatement;
private int filialId;
private int myself;
private int status;
private Date modifyDate;
private String nameNonResident;
private String email;
private Integer typeStatement;
@OneToMany(mappedBy = "statement", cascade = CascadeType.ALL)
private Set<AppCurContract> appCurContracts;
public Statement() {
super();
}
ibeautiful
qq_笑_17
料青山看我应如是
相关分类