gpt4 book ai didi

java - mappedBy 引用了一个未知的目标实体属性

转载 作者:IT老高 更新时间:2023-10-28 13:53:31 24 4
gpt4 key购买 nike

我在带注释的对象中设置一对多关系时遇到问题。

我有以下几点:

@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;


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

还有这个

@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;

我在这里做错了什么

最佳答案

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

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

或将实体属性更改为 customer(我会这样做)。

mappedBy 引用指示“在我收集的东西上查看名为 'customer' 的 bean 属性以查找配置。”

关于java - mappedBy 引用了一个未知的目标实体属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4011472/

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