我是Hibernate注释映射的新手,我正在尝试执行以下映射,这似乎很简单。一个应用 - >可以有多个MissingFacebookAd 问题是MissingFacebookAd有Embeddable复合键,应该是一些如何参考,在我的代码下面请咨询: 的 Application.java
Form imageForm = new Form();
imageForm.Text = "Screenshot";
//imageForm.FormBorderStyle = FormBorderStyle.None;
imageForm.Size = bmpScreenCapture.Size;
imageForm.BackgroundImageLayout = ImageLayout.Zoom;
imageForm.BackgroundImage = bmpScreenCapture;
imageForm.ShowDialog();
MissingFacebookAd.java
Entity
@Cache(region = "application", usage = CacheConcurrencyStrategy.READ_WRITE)
@Table(name= "application")
public class Application implements Serializable {
private long id;
private Advertiser advertiser;
private String name;
private Set<MissingFacebookAd> missingFacebookAd;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", unique = true, nullable = false)
public long getId() {
return id;
}
@OneToMany(mappedBy="id",cascade = CascadeType.REMOVE)
public Set<MissingFacebookAd> getMissingFacebookAdSet() {
return missingFacebookAd;
}
public void setMissingFacebookAd(Set<MissingFacebookAd> missingFacebookAd) {
this.missingFacebookAd = missingFacebookAd;
}
public void setId(long id) {
this.id = id;
}
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name="advertiser_id")
public Advertiser getAdvertiser() {
return advertiser;
}
public void setAdvertiser(Advertiser advertiser) {
this.advertiser = advertiser;
}
@Column(name ="name")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
ApplicationAndFbAdgroupId.java (密钥类)
@Entity
@Table(name= "missing_fb_ad")
public class MissingFacebookAd implements Serializable {
private static final long serialVersionUID = 1L;
private ApplicationAndFbAdgroupId id;
public MissingFacebookAd(Application application, long adgroupIdInTarget) {
ApplicationAndFbAdgroupId id = new ApplicationAndFbAdgroupId(application, adgroupIdInTarget);
this.id = id;
}
private MissingFacebookAd() {
}
@EmbeddedId
public ApplicationAndFbAdgroupId getId() {
return id;
}
public void setId(ApplicationAndFbAdgroupId id) {
this.id = id;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
MissingFacebookAd that = (MissingFacebookAd) o;
if (!id.equals(that.id)) return false;
return true;
}
}
由于