问题
My programm is freezing when I write getters/setters for OneToMany properties.
I have these two entities :
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;
}
}
Why, if I'm not comment the COMPETENCE's getters/setters, my app' is freezing (I believe this is infinite recursion) ? Thanks
来源:https://stackoverflow.com/questions/38147196/hibernate-one-to-many-getters-setters-issues