mappedBy引用一个未知的目标实体属性 [英] mappedBy reference an unknown target entity property

查看:544
本文介绍了mappedBy引用一个未知的目标实体属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有以下几项:

  @MappedSuperclass 
public abstract class MappedModel
{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name =id,nullable = false,unique = true)
private long mId;

然后这个

  @Entity 
@Table(name =customer)
public class Customer extends MappedModel implements Serializable
{

/ **
*
* /
private static final long serialVersionUID = -2543425088717298236L;


/ **收集店铺。 * /
@OneToMany(mappedBy =customer,cascade = CascadeType.ALL,fetch = FetchType.LAZY)
private Collection< Store>专卖店;



  @Entity 
@Table(name =store)
public class Store扩展MappedModel实现Serializable
{

/ **
*
* /
private static final long serialVersionUID = -9017650847571487336L;
$ b $ **许多商店都有一个客户** /
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name =customer_id,referencedColumnName =id ,nullable = false,unique = true)
private Customer mCustomer;

我在这做什么不正确

mappedBy 属性引用 customer ,而属性 mCustomer ,因此是错误消息。因此,将您的映射改为:

  / **商店的集合。 * / 
@OneToMany(mappedBy =mCustomer,cascade = CascadeType.ALL,fetch = FetchType.LAZY)
private Collection< Store>专卖店;

或者将实体属性更改为 customer (这就是我会做的)。

mappedBy引用指出查看名为'customer'的bean属性,查看我收集的东西来查找配置。


I am having an issue in setting up a one to many relationship in my annotated object.

I have the following:

@MappedSuperclass
public abstract class MappedModel
{
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name="id",nullable=false,unique=true)
    private Long mId;

then this

@Entity
@Table(name="customer")
public class Customer extends MappedModel implements Serializable
{

    /**
   * 
   */
  private static final long serialVersionUID = -2543425088717298236L;


  /** The collection of stores. */
    @OneToMany(mappedBy = "customer", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
  private Collection<Store> stores;

and this

@Entity
@Table(name="store")
public class Store extends MappedModel implements Serializable
{

    /**
   * 
   */
  private static final long serialVersionUID = -9017650847571487336L;

  /** many stores have a single customer **/
  @ManyToOne(fetch = FetchType.LAZY)
  @JoinColumn (name="customer_id",referencedColumnName="id",nullable=false,unique=true)
  private Customer mCustomer;

what am i doing incorrect here

解决方案

The mappedBy attribute is referencing customer while the property is mCustomer, hence the error message. So either change your mapping into:

/** The collection of stores. */
@OneToMany(mappedBy = "mCustomer", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private Collection<Store> stores;

Or change the entity property into customer (which is what I would do).

The mappedBy reference indicates "Go look over on the bean property named 'customer' on the thing I have a collection of to find the configuration."

这篇关于mappedBy引用一个未知的目标实体属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆