Description
In Hibernateannotations, many-to-many associations can be defined by @manytomany annotations. At the same time, it is also necessary to describe the correlation table and the associated conditions through annotation @jointable. For bidirectional associations, one end must be defined as owner, and the other end must be defined as inverse (this end will be ignored when the associated table is more sexually manipulated). The associated end does not have to describe the physical mapping, only a simple mappedby parameter, which contains the property name of the principal end, thus binding the relationship between the two parties.
How to make a PO
1 Find out what classes cube--need to introduce:
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
2) Find the car person--the main end:
/** *//**
* Theater
* @author Allen
*/
@SuppressWarnings ("serial")
@Entity
@Table (name = "Theater")
@Cache (usage = cacheconcurrencystrategy.read_write)
public class Theater implements Serializable { br> @ManyToMany (
Targetentity=net.allen.domain.audience.class,
Cascade ={CASCADETYPE.PERSIST,CASC Adetype.merge},
Fetch=fetchtype.lazy
)
@JoinTable (
name= "Theater_audience",
joincolumns={@JoinColumn (name= "theater_id")},
inversejoincolumns={@JoinColumn (name= "audience_id")}
)
@Cache (usage = cacheconcurrencystrategy.nonstrict_read_write)
Private list<audience> audiences = new ARR Aylist<audience> ();
/** *//**
* @return Returns the audiences.
*/
Public list<audience> getaudiences () {
return audiences;
/** *//**
* @param audiences the audiences to set.
*/
Public VOID setaudiences (list<audience> audiences) {
this.audiences = audiences;
}
}