Java Reference
In-Depth Information
@JoinTable(name = "SectionEdition", joinColumns = {
@JoinColumn(name = "sectionId", referencedColumnName = "ID")} ,
inverseJoinColumns = { @JoinColumn(
name = "editionId", referencedColumnName ="ID") } )
public Edition getEdition() {
return edition;
}
public void setEdition(Edition edition) {
this.edition = edition;
}
public void removeArticle(Article article) {
this.getArticles().remove(article);
}
}
The Article entity class
The Article entity has properties id and title , as shown next:
private int id;
private String title;
The Article entity defines NamedQueries findArticleAll , which finds all the
Article entity instances, and findArticleByTitle , which finds an article by title:
@NamedQueries({
@NamedQuery(name="findArticleAll", query="SELECT a FROM Article a"),
@NamedQuery(
name="findArticleByTitle",
query="SELECT a from Article a WHERE a.title = :title")
})
The Article entity is on the many side (the owning side) of a many-to-one
relationship with the Section entity. Once again, a @JoinTable is required on
the owning side. Therefore, add a @ManyToOne annotation with a @JoinTable
annotation. The cascade element is set to cascade MERGE , PERSIST , and
REFRESH operations:
@ManyToOne(cascade={CascadeType.MERGE,
CascadeType.PERSIST, CascadeType.REFRESH})
@JoinTable(name = "ArticleSection", joinColumns = {
@JoinColumn(name="articleId", referencedColumnName="ID")},
inverseJoinColumns = { @JoinColumn(
name="sectionId", referencedColumnName="ID")})
public Section getSection() {
 
Search WWH ::




Custom Search