Java @JsonIgnoreProperties不';我不能在@OneToMany关系中工作

Java @JsonIgnoreProperties不';我不能在@OneToMany关系中工作,java,Java,@JsonIgnoreProperties无法正常工作 我正在编写一个一对多关系,一个属性可以有多个propertySale,我尝试使用@JsonIgnoreProperties来避免无限递归,但由于某种原因,当我试图保存一个propertySale时,它不起作用。有人能告诉我哪里做错了吗 在Property.java中 @Data @Getter @Entity @Table(name = "Property") public class Property { @Id @Gen

@JsonIgnoreProperties无法正常工作

我正在编写一个一对多关系,一个属性可以有多个propertySale,我尝试使用@JsonIgnoreProperties来避免无限递归,但由于某种原因,当我试图保存一个propertySale时,它不起作用。有人能告诉我哪里做错了吗

在Property.java中

@Data
@Getter
@Entity
@Table(name = "Property")
public class Property {
    @Id
    @GeneratedValue
    private Long id;
    ...
    @OneToMany(mappedBy="property", cascade = CascadeType.ALL, targetEntity = PropertySale.class)
    @JsonIgnoreProperties("property")
    private Set<PropertySale> propertySales = new HashSet<>();
    ...
    public void addPropertySale(PropertySale propertySale){
        this.propertySales.add(propertySale);
    }

}
在PropertySaleServiceImp.java中

@Service
public class PropertySaleServiceImp implements PropertySaleService{

    @Autowired
    private PropertySaleRepository propertySaleRepository;
    @Autowired
    private PropertyRepository propertyRepository;

    @Override
    public ResponseEntity<PropertySale> savePropertySale(PropertySale propertySale) {
        Optional<Property> existPropertyOpt = this.propertyRepository.findById(propertySale.getProperty().getId());

        if(existPropertyOpt.isPresent()){
            Example<PropertySale> propertySaleExample =  Example.of(propertySale);
            Optional<PropertySale> existPropSale = this.propertySaleRepository.findOne(propertySaleExample);
            if(existPropSale.isPresent()){
                throw new PropertySaleAlreadyExistException();

            }else{
                Property existProperty = existPropertyOpt.get();
                propertySale.setProperty(existProperty);
                existProperty.addPropertySale(propertySale);
                this.propertyRepository.save(existProperty);
                return new ResponseEntity<>(propertySale, HttpStatus.CREATED);
            }

        }else{
            throw new PropertyNotFoundException(propertySale.getProperty().getId());
        }
    }
@服务
公共类PropertySaleServiceImp实现PropertySaleService{
@自动连线
私人财产租赁财产租赁财产租赁财产;
@自动连线
私人财产存储财产存储财产;
@凌驾
公共响应属性savePropertySale(PropertySale PropertySale){
可选existPropertyOpt=this.propertyRepository.findById(propertySale.getProperty().getId());
if(existPropertyOpt.isPresent()){
Example PropertySaleXample=Example.of(propertySale);
可选existPropSale=this.propertySalrepository.findOne(propertySaleExample);
if(existPropSale.isPresent()){
抛出新属性LealReadyExistException();
}否则{
属性existProperty=existPropertyOpt.get();
propertySale.setProperty(existProperty);
existProperty.addPropertySale(propertySale);
this.propertyRepository.save(existProperty);
返回新的响应属性(propertySale、HttpStatus.CREATED);
}
}否则{
抛出新的PropertyNotFoundException(propertySale.getProperty().getId());
}
}
我明白了 org.springframework.web.util.NestedServletException:处理程序调度失败;嵌套异常为java.lang.StackOverflower错误 当行
this.propertyRepository.save(existProperty);

已执行。

JsonIgnoreProperties注释错误。请从属性类中删除@JsonIgnoreProperties并设置@JsonIgnoreProperties(“属性”)在属性属性处的PropertySale实体上。感谢您的回答,但在执行您所说的操作后,我得到了“java.sql.SQLNonTransientConnectionException:不允许公钥检索”,您知道为什么会发生这种情况吗?谢谢。JsonIgnoreProperties注释错误。请从属性类中删除@JsonIgnoreProperties并设置@JsonIgnoreProperties属性属性处的PropertySale实体上的证书(“属性”)。感谢您的回答,但我得到了“java.sql.SQLNonTransientConnectionException:不允许检索公钥”的答案。在执行您所说的操作后,您知道为什么会发生这种情况吗?谢谢。
@Service
public class PropertySaleServiceImp implements PropertySaleService{

    @Autowired
    private PropertySaleRepository propertySaleRepository;
    @Autowired
    private PropertyRepository propertyRepository;

    @Override
    public ResponseEntity<PropertySale> savePropertySale(PropertySale propertySale) {
        Optional<Property> existPropertyOpt = this.propertyRepository.findById(propertySale.getProperty().getId());

        if(existPropertyOpt.isPresent()){
            Example<PropertySale> propertySaleExample =  Example.of(propertySale);
            Optional<PropertySale> existPropSale = this.propertySaleRepository.findOne(propertySaleExample);
            if(existPropSale.isPresent()){
                throw new PropertySaleAlreadyExistException();

            }else{
                Property existProperty = existPropertyOpt.get();
                propertySale.setProperty(existProperty);
                existProperty.addPropertySale(propertySale);
                this.propertyRepository.save(existProperty);
                return new ResponseEntity<>(propertySale, HttpStatus.CREATED);
            }

        }else{
            throw new PropertyNotFoundException(propertySale.getProperty().getId());
        }
    }