简体   繁体   English

一对一未知映射

[英]OnetoOne unknown mappedBy

I am getting a mappedBy unknown error between the relatioships of the following two entities. 我在以下两个实体的关系之间遇到了一个不正确的mapdBy错误。

It is a one to one relationship and the owner of the relationship should be the Story entity. 这是一对一关系,关系的所有者应该是Story实体。 I can't see my mistake in this code. 我在这段代码中看不到我的错误。

Both entities have getters and setters. 两个实体都有吸气剂和吸气剂。

This is the first entity: 这是第一个实体:

@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 + '\'' +
                '}';
    }
}

This is the second entity: 这是第二个实体:

   @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+ '\'' +
                '}';
    }
}

EDIT 编辑

Stacktrace: 堆栈跟踪:

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

EDIT 2 编辑2

I tried adding @PrimaryKeyJoinColumn instead of @JoinColumn in Design Entity, getting same error. 我尝试在设计实体中添加@PrimaryKeyJoinColumn而不是@JoinColumn,得到相同的错误。

I have generated the getters and setters in both entities. 我已经在两个实体中生成了getter和setter。 So no typo's in these things. 因此,在这些方面没有错别字。

It could be a hibernate bug !! 可能是一个休眠错误! see this : 看到这个:

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

Try to change the version of hibernate that you use. 尝试更改您使用的休眠版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM