OnetoOne未知的mappedBy

时间:2017-10-20 08:05:48

标签: java spring hibernate

我在以下两个实体的关系之间得到了一个mappedBy未知错误。

这是一对一的关系,关系的所有者应该是Story实体。我在这段代码中看不到我的错误。

两个实体都有吸气剂和固定剂。

这是第一个实体:

@Entity
@Table(name = "story")
public class Story {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;

    private String name;

    private String link;

    @OneToOne(mappedBy = "story", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private DesignTechnique designTechnique;


    public Story(){

    }

    public Story(String name, String link){
        this.name = name;
        this.link= link;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getLink() {
        return link;
    }

    public void setLink(String link) {
        this.link= link;
    }

    public DesignTechnique getDesignTechnique() {
        return designTechnique;
    }

    public void setDesignTechnique(DesignTechnique designTechnique) {
        this.designTechnique = designTechnique;
    }

    @Override
    public String toString() {
        return "UserStory{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", link='" + link+ '\'' +
                ", designTechnique='" + designTechnique + '\'' +
                '}';
    }
}

这是第二个实体:

   @Entity
@Table(name = "designTechnique")
public class DesignTechnique {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;

    private String technique;

    @OneToOne
    @JoinColumn(name = "story_ID")
    private Story story;


    public DesignTechnique(){

    }

    public DesignTechnique(String technique){
        this.technique = technique;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getTechnique() {
        return technique;
    }

    public void setTechnique(String technique) {
        this.technique = technique;
    }

    public Story getStory() {
        return story;
    }

    public void setStory(Story story) {
        this.story = story;
    }

    @Override
    public String toString() {
        return "TestdesignTechnique{" +
                "id=" + id +
                ", technique='" + technique + '\'' +
                ", story='" + story+ '\'' +
                '}';
    }
}

修改

堆栈跟踪:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: Unknown mappedBy in: com.clusters.Model.Story.designTechnique, referenced property unknown: com.clusters.Model.DesignTechnique.story

编辑2

我尝试在设计实体中添加@PrimaryKeyJoinColumn而不是@JoinColumn,但同样的错误。

我在两个实体中都生成了getter和setter。所以在这些事情上没有错字。

1 个答案:

答案 0 :(得分:0)

这可能是一个冬眠虫!看到这个:

https://hibernate.atlassian.net/browse/HHH-5695

尝试更改您使用的hibernate版本。