gpt4 book ai didi

java - 一对一未知映射者

转载 作者:太空宇宙 更新时间:2023-11-04 11:01:34 25 4
gpt4 key购买 nike

我在以下两个实体的关系之间收到了一个 MapBy Unknown 错误。

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

两个实体都有 getter 和 setter。

这是第一个实体:

@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。所以这些东西没有错别字。

最佳答案

这可能是一个 hibernate 错误!看到这个:

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

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

关于java - 一对一未知映射者,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46844799/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com