当我为OneToMany属性编写getter / setter时,我的程序正在冻结。
我有这两个实体:
COMPETENCE_LEVEL
@Entity
@Table(name="competence_level")
public class CompetenceLevel {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="id_competence_level")
private Long idCompetenceLevel;
@ManyToOne
@JoinColumn(name="id_competence")
private Competence competence;
@ManyToOne
@JoinColumn(name="id_level")
private Level level;
@ManyToOne
@JoinColumn(name="id_profil")
private Profil profil;
public CompetenceLevel() {
super();
}
public CompetenceLevel(Competence competence, Level level, Profil profil) {
super();
this.competence = competence;
this.level = level;
this.profil = profil;
}
/**
* @return the idCompetenceLevel
*/
public Long getIdCompetenceLevel() {
return idCompetenceLevel;
}
/**
* @param idCompetenceLevel the idCompetenceLevel to set
*/
public void setIdCompetenceLevel(Long idCompetenceLevel) {
this.idCompetenceLevel = idCompetenceLevel;
}
/**
* @return the competence
*/
public Competence getCompetence() {
return competence;
}
/**
* @param competence the competence to set
*/
public void setCompetence(Competence competence) {
this.competence = competence;
}
/**
* @return the level
*/
public Level getLevel() {
return level;
}
/**
* @param level the level to set
*/
public void setLevel(Level level) {
this.level = level;
}
/**
* @return the profil
*/
public Profil getProfil() {
return profil;
}
/**
* @param profil the profil to set
*/
public void setProfil(Profil profil) {
this.profil = profil;
}
}
COMPETENCE
@Entity
@Table(name="competence")
public class Competence {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="id_competence")
private Long idCompetence;
@Column(name="libelle")
private String libelle;
@OneToMany(mappedBy="competence", cascade=CascadeType.ALL)
private List<CompetenceLevel> competenceLevels;
public Competence() {
super();
}
public Competence(String libelle) {
super();
this.libelle = libelle;
}
public Long getIdCompetence() {
return idCompetence;
}
public void setIdCompetence(Long idCompetence) {
this.idCompetence = idCompetence;
}
public String getLibelle() {
return libelle;
}
public void setLibelle(String libelle) {
this.libelle = libelle;
}
// ISSUE !!!
public List<CompetenceLevel> getCompetenceLevels() {
return competenceLevels;
}
// ISSUE !!!
public void setCompetenceLevels(List<CompetenceLevel> competenceLevels) {
this.competenceLevels = competenceLevels;
}
}
为什么,如果我不评论COMPETENCE的getter / setter,我的应用程序'冻结了(我相信这是无限递归)?谢谢