注册 登录
编程论坛 JAVA论坛

hibernate的映射问题

hailang466 发布于 2018-03-26 10:55, 1549 次点击
各们大牛们有个问题请教,我现在有三个类,Creator是父类,它有一个属性是MpAccount这是一个类protected修饰,AccountFan继承了Creator,在MpAccount这个类中有一个List<AccountFan>属性这里面配置了一对多,但在编译的时候报找不到AccountFan的MpAccount这个属性,实际上应该已经继承了的啊 为什么还这样那?
@Entity
@Table(name="we_creator")
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
public class  Creator extends IdEntity{

    protected String openId;//openId,每个用户都是唯一的
    protected Integer subscribeStatus;//订阅状态
    protected String subscribeTime;//订阅时间
    protected byte[] nickname;//昵称,二进制保存emoji表情
    protected String nicknameStr;//昵称显示
    protected String wxid;//微信号
    protected Integer gender;//性别 0-女;1-男;2-未知
    protected String language;//语言
    protected String country;//国家
    protected String province;//省
    protected String city;//城市
    protected String headimgurl;//头像
    protected String remark;//备注
    protected Integer status;//用户状态 1-可用;0-不可用
    protected Date Createtime;
    public MpAccount mpAccount;
    @ManyToOne(cascade=CascadeType.ALL,optional=false)
    @JoinColumn(name="account_id",referencedColumnName="id")
    public MpAccount getMpAccount() {
        return mpAccount;
    }
    public void setMpAccount(MpAccount mpAccount) {
        this.mpAccount = mpAccount;
    }
}
@Entity
@Table(name="we_fans")
public class AccountFans extends Creator{}


@Entity
@Table(name = "we_mpaccount")
public class MpAccount extends IdEntity implements Serializable{
    private static final long serialVersionUID = -6315146640254918207L;
   
   
    private String account;//账号
    private String appid;//appid
    private String appsecret;//appsecret
    private String url;//验证时用的url
    private Integer status;
    private Date createDate;
    private Integer type;
    private String openid;
   
    private List<AccountFans> fanes = new ArrayList<AccountFans>();
@OneToMany(mappedBy="mpAccount",cascade=CascadeType.PERSIST,fetch=FetchType.LAZY)
    public List<AccountFans> getFanes() {
        return fanes;
    }
    public void setFanes(List<AccountFans> fanes) {
        this.fanes = fanes;
    }
}

报的错误Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.hailang.wechat.model.AccountFans.mpAccount in com.hailang.wechat.model.MpAccount.fanes
2 回复
#2
疯狂的小a2018-03-26 14:00
@OneToMany(mappedBy="mpAccount",cascade=CascadeType.PERSIST,fetch=FetchType.LAZY)target是不是没有配
#3
疯狂的小a2018-03-26 14:24
IdEntity你的这个类呢
1