Hi,
I can't figure out why once I'm been trying to load a many to many relation (the datas are correctly stored into the database) but when I access the collection the set is null
here is how I try to load the data
Code:
public Set<Personne> getBeneficaireEnfants() {
DossierBeneficiaire dossierBeneficiaire = dossierBeneficiaireService.findByCriteriaMainBeneficiaire(dossier);
if (dossierBeneficiaire != null) {
try {
LOG.debug("DOSSIER BENEFICIAIRE NOT NULL");
LOG.debug("ENFANT SIZE : " + dossierBeneficiaire.getBeneficiairesEnfant().size());
return dossierBeneficiaire.getBeneficiairesEnfant();
}
catch (Exception ex) {
LOG.debug("Exception while attempting to retrieve enfant " + ex);
return null;
}
}else {
return null;
}
dossier beneficiare is not null but ENFANT SIZE get 0
here is my entity
Code:
@Entity
public class DossierBeneficiaire implements Serializable{
/** The serial version id. */
private static final long serialVersionUID = 0;
/** The dossier beneficiaire id. */
@Id
@Column(name="id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
/** The dossier id. */
@ManyToOne(fetch = FetchType.EAGER, optional = true)
@Cascade((org.hibernate.annotations.CascadeType.SAVE_UPDATE))
private Dossier dossier;
/** The date debut. */
@Column(name="dateDebut", nullable=true)
private Date dateDebut;
/** The date fin. */
@Column(name="dateFin", nullable=true)
private Date dateFin;
/** The beneficiaire adulte. */
@ManyToMany(fetch = FetchType.EAGER)
@Cascade((org.hibernate.annotations.CascadeType.SAVE_UPDATE))
@JoinTable(name = "DossierBeneficiaire_BeneficiaireAdulte",
joinColumns = @JoinColumn(name="dossierBeneficiaire_fk"),
inverseJoinColumns = @JoinColumn(name="personne_fk")
)
private Set<Beneficiaire> beneficiairesAdulte;
/** The beneficiaire enfant . */
@ManyToMany(fetch = FetchType.EAGER)
@Cascade((org.hibernate.annotations.CascadeType.SAVE_UPDATE))
@JoinTable(name = "DossierBeneficiaire_BeneficiaireEnfant",
joinColumns = @JoinColumn(name="dossierBeneficiaire_fk"),
inverseJoinColumns = @JoinColumn(name="personne_fk")
)
private Set<Personne> beneficiairesEnfant;
/** The beneficiaire tiers . */
@ManyToMany(fetch = FetchType.EAGER)
@Cascade((org.hibernate.annotations.CascadeType.SAVE_UPDATE))
@JoinTable(name = "DossierBeneficiaire_BeneficiaireTiers",
joinColumns = @JoinColumn(name="dossierBeneficiaire_fk"),
inverseJoinColumns = @JoinColumn(name="personne_fk")
)
private Set<Personne> beneficiairesTiers;
/**
* Constructor
*/
public DossierBeneficiaire() {
beneficiairesAdulte = new HashSet<Beneficiaire>();
beneficiairesEnfant = new HashSet<Personne>();
beneficiairesTiers = new HashSet<Personne>();
}
/**
* Gets the BeneficiaireEnfants
*
* @return Set<Beneficiaire> returns the BeneficairesEnfant
*/
public Set<Personne> getBeneficiairesEnfant() {
return beneficiairesEnfant;
}
/**
* Sets the BeneficiaireEnfants
*
* @param beneficiairesEnfant
* The set of beneficiaire enfants to set
*/
public void setBeneficiairesEnfant(Set<Personne> beneficiairesEnfant) {
this.beneficiairesEnfant = beneficiairesEnfant;
}
/**
* Gets the BeneficaireTiers
*
* @return Set<Beneficiaire> returns the set of beneficiaire
*
*/
public Set<Personne> getBeneficiairesTiers() {
return beneficiairesTiers;
}
/**
* Sets the BeneficaireTiers
*
* @param beneficiairesTiers
* The beneficiaire tiers to set
*/
public void setBeneficiairesTiers(Set<Personne> beneficiairesTiers) {
this.beneficiairesTiers = beneficiairesTiers;
}
/**
* Gets the id
*
* @return long returns the id
*/
public long getId() {
return id;
}
/**
* Sets the id
*
* @param id
* The id to set
*/
public void setId(long id) {
this.id = id;
}
/**
* Gets the Dossier
*
* @return Dossier returns the DossierId
*/
public Dossier getDossier() {
return dossier;
}
/**
* Sets the Dossier
*
* @param dossier
* The Dossier to set
*/
public void setDossier(Dossier dossier) {
this.dossier = dossier;
}
/**
* Gets the date debut
*
* @return Date returns the date debut
*/
public Date getDateDebut() {
return dateDebut;
}
/**
* Sets the date debut
*
* @param dateDebut
* The date debut to set
*/
public void setDateDebut(Date dateDebut) {
this.dateDebut = dateDebut;
}
/**
* Gets the date fin
*
* @return Date returns the date fin
*/
public Date getDateFin() {
return dateFin;
}
/**
* Sets the date fin
*
* @param dateFin
* The date fin to set
*/
public void setDateFin(Date dateFin) {
this.dateFin = dateFin;
}
/**
* Gets the Beneficiaire
*
* @return Beneficiaire returns the Beneficiaire
*/
public Set<Beneficiaire> getBeneficiairesAdulte() {
return beneficiairesAdulte;
}
/**
* Sets the Beneficiaire
*
* @param beneficiaire
* The Benficiaire to set
*/
public void setBeneficiairesAdulte(Set<Beneficiaire> beneficiairesAdulte) {
this.beneficiairesAdulte = beneficiairesAdulte;
}
/**
* Does our two object are equals ?
*
* @param obj
* The object to compare to
* @return boolean returns true if the gived paramater is equal to our current object
*
*/
@Override
public boolean equals(Object obj) {
return EqualsBuilder.reflectionEquals(this, obj);
}
/**
* Gets the hash code
*
* @return int return the hash code of the current adresse
*/
@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
/**
* Make a String representation of the current adresse
*/
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
}
}