43
我在設置註釋對象中的一對多關係時遇到問題。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;
/** 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;
我在做什麼這裏不正確
工作,我曾預計它使用反射使用setter或getter方法,而不是直接屬性。 – boyd4715 2010-10-25 03:11:59
@ boyd4715:您可以嘗試在getter上移動註釋,以查看使用屬性訪問(vs字段訪問)時會發生什麼情況。另一方面,'mappedBy'的javadoc表示*擁有關係的字段*,所以我不確定這會改變什麼。 – 2010-10-25 03:24:03
工作,感謝您的快速澄清 – 2016-02-23 06:29:24