mappedBy引用一个未知的目标实体属性
我有一个问题,在我的注释对象中build立一对多的关系。
我有以下几点:
@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属性,我有一个集合来查找configuration。
- 你如何做HQL限制查询?
- Hibernatevalidation器:@Email接受ask @ stackoverflow为有效的?
- hibernate/春季:未能懒惰地初始化 – 没有会议或会议被closures
- Criteria.DISTINCT_ROOT_ENTITY vs Projections.distinct
- Hibernate Criteria Query来获取特定的列
- 在双向JPA OneToMany / ManyToOne关联中,“关联的反面”是什么意思?
- Hibernate如何检测实体对象的脏状态?
- 如何在JPA(和相应的连接表行)中删除具有ManyToMany关系的实体?
- Hibernate:如何用HQL设置NULL查询参数值?