Java Reference
In-Depth Information
The Section entity is on the owning side (many side) of a many-to-one relationship
with the Edition entity. Specify 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 = "SectionEdition",
joinColumns = { @JoinColumn(
name = "sectionId",referencedColumnName = "ID") } ,
inverseJoinColumns = { @JoinColumn(
name = "editionId", referencedColumnName ="ID") } )
public Edition getEdition() {
return edition;
}
The Section entity also has a one-to-many relationship with the Article entity. The
Section entity is the non-owning side of the one-to-many relationship, but to be
able to initiate cascade operations from the Section entity, we shall add a join table
on the Section entity side. The section field specified in the mappedBy element is
defined in the Article entity class:
@OneToMany(cascade={CascadeType.ALL},mappedBy = "section")
@JoinTable(name = «SectionArticle», joinColumns = {
@JoinColumn(name=»sectionId», referencedColumnName=»ID»)},
inverseJoinColumns = { @JoinColumn(
name=»articleId», referencedColumnName=»ID»)})
public List<Article> getArticles() {
return articles;
}
The Section entity is listed next:
package model;
import java.io.Serializable;
import java.util.List;
import javax.persistence.*;
@Entity
@NamedQueries({
@NamedQuery(name="findSectionAll", query="SELECT s FROM Section s"),
@NamedQuery(
name="findSectionBySectionName",
 
Search WWH ::




Custom Search