【问题标题】:MappedBy reference an unknown target entityMappedBy 引用了一个未知的目标实体
【发布时间】:2017-10-07 13:34:44
【问题描述】:

我在数据库中为电影服务设计了一个表系统。到目前为止,我都是这样设计它们的。

@Entity
@Table(name = "movies")
@Data
public class MovieEntity {

    @Id
    @Column(unique = true, updatable = false)
    @GeneratedValue
    private Long id;

    @OneToMany(mappedBy = "movie", cascade = CascadeType.ALL)
    private Set<MovieDescription> description;
}

@Entity
@Table(name = "movies_info")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "type")
public abstract class MovieInfo {

    @Id
    @Column(unique = true, updatable = false)
    @GeneratedValue
    private Long id;

    @ManyToOne
    public MovieEntity movie;
}

@Entity
@DiscriminatorValue(value = EditType.Values.DESCRIPTION)
public class MovieDescription extends MovieInfo {

    private String description;
    private String language;
}

编译的时候报错

Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.core.jpa.entity.MovieDescription.movie in com.core.jpa.entity.MovieEntity.description

与 MovieEnity 映射有关的东西,但我不知道它是什么。

【问题讨论】:

  • 您是否使用代码优先方法?如果不是,请提供数据库架构

标签: java spring hibernate spring-mvc spring-boot


【解决方案1】:

使用 targetEntity 属性来定位您要映射的超类字段。

@Entity
@Table(name = "movies")
@Data
public class MovieEntity {

    @Id
    @Column(unique = true, updatable = false)
    @GeneratedValue
    private Long id;

    @OneToMany(mappedBy = "movie", cascade = CascadeType.ALL, targetEntity= MovieInfo.class)
    private Set<MovieDescription> description;
}

更多详情:one to many mapping to a property of superclass

【讨论】:

    猜你喜欢
    • 2021-05-02
    • 1970-01-01
    • 2011-04-30
    • 1970-01-01
    • 2022-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多