spring 异常错误:mappedBy引用未知目标实体属性?

j5fpnvbx  于 2022-11-28  发布在  Spring
关注(0)|答案(1)|浏览(113)

异常错误:mappedBy引用未知目标实体属性:在www.example.com中显示用户配置文件com.vitoria.models.UserProfile.show
嗨!我正在尝试开发一个将UserProfile类型与Show recommendations相关联的系统,现在我正在做一些基本的工作:我尝试了很多mappedBy和不同注解的组合,但似乎都不起作用。
下面是我的代码:
使用者设定档:

package com.vitoria.models;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

@Entity
@Table(name="user_profile")
public class UserProfile implements Serializable{
    
    private static final long serialVersionUID = 1L;
    
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name="user_profile_id")
    private Integer id;
    
    @Column(name="user_profile_type")
    private String type;
    
    @OneToOne(mappedBy="user_profile")
    private User user;
    
    @OneToMany(mappedBy="user_profile")
    private List<Show> show;

    public UserProfile() {
        super();
    }

    public UserProfile(Integer id, String type, User user, List<Show> show) {
        super();
        this.id = id;
        this.type = type;
        this.user = user;
        this.show = show;
    }

    public Integer getId() {
        return id;
    }

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

    public String getType() {
        return type;
    }

    public void ListType(String type) {
        this.type = type;
    }

    public User getUser() {
        return user;
    }

    public void ListUser(User user) {
        this.user = user;
    }

    public List<Show> getshow() {
        return show;
    }

    public void ListShow(List<Show> show) {
        this.show= show;
    }
}

显示:

package com.vitoria.models;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name="show")
public class Show implements Serializable{
    private static final long serialVersionUID = 1L;
    
    @Column(name="show_name", unique=true)
    private String name;
    
    @Column(name="show_genre")
    private String genre;
    
    @Column(name="show_synopsis")
    private String synopsis;
    
    @Column(name="show_id")
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Id
    private Integer id;
    
    @ManyToOne(cascade = CascadeType.PERSIST)
    @JoinColumn(name="user_profile_id")
    private UserProfile userProfile;

    public Show() {
    }

    public Show(String name, String genre, String synopsis, Integer id, UserProfile userProfile) {
        this.name = name;
        this.genre = genre;
        this.synopsis = synopsis;
        this.id = id;
        this.userProfile = userProfile;
    }

    public String getName() {
        return name;
    }

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

    public String getGenre() {
        return genre;
    }

    public void setGenre(String genre) {
        this.genre = genre;
    }

    public String getSynopsis() {
        return synopsis;
    }

    public void setSynopsis(String synopsis) {
        this.synopsis = synopsis;
    }

    public Integer getId() {
        return id;
    }

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

    public UserProfile getUserProfile() {
        return userProfile;
    }

    public void setUserProfile(UserProfile userProfile) {
        this.userProfile = userProfile;
    }
}

我知道问题出在注解上,但不知道出在哪里。如果有人能告诉我如何解决这个问题,我会非常感激!〈3

14ifxucb

14ifxucb1#

您误用了mappedBy属性。它必须包含Java类属性的名称。而不是列的名称。

相关问题