Erreur de type : LazyInitializationException
Bonjour,
Dans le cadre d'un développement JAVA je me dois d'implémenter ce modèle de donnée (qui fait parti d'un plus gros ensemble) :
http://img24.imageshack.us/img24/7058/sansre2a.jpg
Ma relation ManyToMany possède des attributs.Je n'ai donc pas le droit d'utiliser l'annotation @ManyToMany. Je suis obligé de passer par une classe qui fera ma liaison avec deux annotations @ManyToOne
Mes classes sont donc :
Classe Prestation
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
@Entity
public class Prestation implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String intitulé ;
@Temporal(javax.persistence.TemporalType.DATE)
private Date date_début;
@OneToMany(mappedBy = "prestation" )
private List<Entity_Liaison_Intervenant_prestation> liaison_Intervenant = new ArrayList<Entity_Liaison_Intervenant_prestation> (); |
Classe Intervenant
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
@Entity
public class Intervenant implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String nom;
private String prénom;
@OneToMany(mappedBy = "intervenant")
private List<Entity_Liaison_Intervenant_prestation> liaison_Prestation = new ArrayList<Entity_Liaison_Intervenant_prestation> (); |
Classe Liaison
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
@Entity
public class Entity_Liaison_Intervenant_prestation implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private static final long serialVersionUID = 1L;
@ManyToOne(fetch = FetchType.EAGER, optional = false)
private Intervenant intervenant;
@ManyToOne(fetch = FetchType.EAGER, optional = false)
private Prestation prestation;
@Temporal(javax.persistence.TemporalType.DATE)
private Date date;
@Enumerated(EnumType.STRING)
private Etat_Intervenant role_intervenant; |
J'ajoute sans problème un nouvel intervenant à ma prestation :
Code:
1 2 3 4 5 6
|
Intervenant intervenant_à_ajouter = (Intervenant)comboIntervenants.getSelectedObjects()[0];
Entity_Liaison_Intervenant_Prestation liaison_à_ajouter = new Entity_Liaison_Intervenant_Prestation();
liaison_à_ajouter.setRole_intervenant(Etat_Intervenant.babysitter);
liaison_à_ajouter.setIntervenant(intervenant_à_ajouter);
liaison_à_ajouter.setPrestation(PrestationEnCours); |
En revanche, quand je veux récupérer tous mes intervenants qui ont eu un rôle pendant ma prestation, et bien c'est le drame :
Code:
1 2
| 16 sept. 2011 14:04:02 org.hibernate.LazyInitializationException <init>
GRAVE: failed to lazily initialize a collection of role: application.entity.Prestation.liaison_Intervenant, no session or session was closed |
Mon code qui appelle l'erreur :
Code:
1 2
| for (Entity_Liaison_Intervenant_Prestation liaison : PrestationEnCours.getLiaison_Intervenant())
System.out.println(liaison.getId()); |
Bref je comprend pas pourquoi j'ai une erreur "Lazy" alors que ma relation est annotée FetchType.EAGER (qui d'ailleurs est le comportement par défaut) !
Merci d'avance pour vos conseils !