无法使用spring data jpa

时间:2017-09-16 11:11:11

标签: java hibernate jpa spring-boot spring-data-jpa

我是Spring数据JPA的新手。我有两个表infodetailsdetailsCPDT_CP_ID是外键,CPDT_ID是主键。 infoCP_ID是主键。

Details.java

@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "CP_ID")
private Info info;

public Info getInfo() {
    return info;
}

public Details() {

}

public Details setInfo(Info info) {
    this.info= info;
    return this;
} ////// Others getters and setters

info.java

@OneToOne(mappedBy = "info")
private Details details;

public CorpDetails getCorpDetails() {
        return corpDetails;
}
public void setDetails(Details details) {
        this.details = details;
}

在我的controller.java中

Detailsobj.setInfo(Info);
DetailsService.saveDetails(Detailsobj); 

我收到ORA-00904:"CP_ID":无效的标识符。但我怀疑CP_ID不是details表,它在信息表中。 请帮帮我,我的错误在哪里。

提前致谢

1 个答案:

答案 0 :(得分:0)

@JoinColumn中,您应该指定引用主表的列的名称,该列具有指向主表的id的外键。因此,在您的情况下,如果CPDT_CP_ID中的details具有CP_ID info@OneToOne(cascade = CascadeType.ALL) @JoinColumn(name = "CPDT_CP_ID") private Info info; 表的外键,则应该放置:

$(document).ready(function() {

  var currentHeight = $(document).height();
  /*alert(currentHeight);*/

  var currentFooter = currentHeight - 50;

  $('footer').css("bottom", currentFooter);

  $(window).on('scroll', function() {
    /*var navHeight = $(window ).height() - 67;*/

    var heHeight = $('.header').height();

    if ($(window).scrollTop() > heHeight) {
      $('nav').addClass('sticky');
    } else {
      $('nav').removeClass('sticky');
    }
  });
});