gpt4 book ai didi

java - Hibernate 找不到 map 属性

转载 作者:行者123 更新时间:2023-12-02 12:27:32 25 4
gpt4 key购买 nike

所以我得到了异常:org.hibernate.AnnotationException:mappedBy引用未知目标实体属性:se.mulander.cosmos.movi​​es.model.Cast.starredIn in se.mulander.cosmos.movi​​es.model.ExtendedMovie.cast

但我实在不明白为什么。我要映射的两个对象是:

@Entity
@Table(name = "cast")
@ApiModel(description = "A cast member that has been part of making the movie")
public class Cast
{
@JsonIgnore
@ManyToOne(fetch = FetchType.EAGER, cascade = {CascadeType.ALL})
@JoinColumn(name = "movie_id")
public ExtendedMovie starredIn;
}

@Entity
@Table(name = "extended_movie")
public class ExtendedMovie
{
@OneToMany(cascade = {CascadeType.ALL}, mappedBy = "starredIn", orphanRemoval = true)
@LazyCollection(LazyCollectionOption.FALSE)
public List<Cast> cast = new ArrayList<>();
}

我已经剥离了它们的一些其他属性,但本质上这是不起作用的关系。

所以我不明白的是为什么它说它是一个未知属性,因为该属性是公共(public)的并且 hibernate 在映射它时不应该有任何问题。

我在这里缺少什么?

最佳答案

尝试这样的事情:

扩展电影:

@Entity
public class ExtendedMovie implements Serializable {
private static final long serialVersionUID = 6771189878622264738L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true)
@JoinColumn(name = "cast_id", referencedColumnName = "id")
private Set<Cast> cast;

public Set<Cast> getCast() {
return cast;
}

public void setCast(Set<Cast> cast) {
this.cast= cast;
}
}

Actor 阵容:

@Entity
@ApiModel(description = "A cast member that has been part of making the movie")
public class Cast implements Serializable {
private static final long serialVersionUID = 6771189878622265738L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
//Remove extendedmovie from here
//other property getter and setters here
}

这将在 ExtendedMovie 和 Cast 之间建立一对多关系。

关于java - Hibernate 找不到 map 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45425277/

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