IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Hibernate Java Discussion :

[Hibernate] Exception LazyInitializationException


Sujet :

Hibernate Java

  1. #1
    Membre éclairé Avatar de agougeon
    Inscrit en
    Mai 2005
    Messages
    253
    Détails du profil
    Informations forums :
    Inscription : Mai 2005
    Messages : 253
    Par défaut [Hibernate] Exception LazyInitializationException
    Bonjour, j'utilise pas spring et j'ai lerreur suivante
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
    Exception in thread "main" ERROR - could not initialize proxy - the owning Session was closed
    org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
    	at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:53)
    	at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:84)
    	at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:134)
    	at fr.planning.pojo.Collaborateur$$EnhancerByCGLIB$$d9c24562.getNom(<generated>)
    	at fr.planning.pojo.dao.ProfilDAO.main(ProfilDAO.java:39)
    org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
    	at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:53)
    	at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:84)
    	at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:134)
    	at fr.planning.pojo.Collaborateur$$EnhancerByCGLIB$$d9c24562.getNom(<generated>)
    	at fr.planning.pojo.dao.ProfilDAO.main(ProfilDAO.java:39)
    Voila mon fichier de mapping
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
     
    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC
    	"-//Hibernate/Hibernate Mapping DTD//EN"
    	"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
     
    <hibernate-mapping package="fr.planning.pojo">
    	<class
    		name="Profil"
    		table="PROFIL"
    	>
    		<id
    			name="id"
    			type="integer"
    			column="PRO_ID"
    		>
    			<generator class="native"/>
    		</id>
     
    		<property
    			name="dateDispo"
    			column="PRO_DATE_DISPO"
    			type="date"
    			not-null="false"
    			length="10"
    		/>
    		<property
    			name="droit"
    			column="PRO_DROIT"
    			type="integer"
    			not-null="false"
    			length="11"
    		/>
    		<property
    			name="type_utilisateur"
    			column="PRO_UTILISATEUR"
    			type="java.lang.Boolean"
    			not-null="false"
    			length="1"
    		/>
    		<property
    			name="commercial"
    			column="PRO_COMMERCIAL"
    			type="java.lang.Boolean"
    			not-null="false"
    			length="1"
    		/>
    		<property
    			name="reserver"
    			column="PRO_RESERVER"
    			type="java.lang.Boolean"
    			not-null="false"
    			length="1"
    		/>
     
    		<property
    			name="siege"
    			column="PRO_SIEGE"
    			type="java.lang.Boolean"
    			not-null="false"
    			length="1"
    		/>
    		<property
    			name="mobilite"
    			column="PRO_MOBILITE"
    			type="java.lang.Boolean"
    			not-null="false"
    			length="1"
    		/>
     
    		<many-to-one
    			name="situation"
    			column="SIT_ID"
    			class="Situation"
    			not-null="false"
    		>
     
    		</many-to-one>
    		<many-to-one
    			name="client"
    			column="CLT_ID"
    			class="Client"
    			not-null="false"
    		>
    		</many-to-one>
    		<many-to-one
    			name="societe"
    			column="SOC_ID"
    			class="Societe"
    			not-null="false"
    		>
    		</many-to-one>
    		<many-to-one
    			name="fonction"
    			column="RFN_ID"
    			class="Fonction"
    			not-null="false"
    		>
    		</many-to-one>
    		<many-to-one
    			name="collaborateur"
    			column="COL_ID"
    			class="Collaborateur"
    			not-null="false"
    		>
    		</many-to-one>
    		<many-to-one
    			name="statut"
    			column="STT_ID"
    			class="Statut"
    			not-null="false"
    		>
    		</many-to-one>
    		<many-to-one
    			name="utilisateur"
    			column="UTL_ID"
    			class="Utilisateur"
    			not-null="false"
    		>
    		</many-to-one>
     
    		<set
    			name="entites"
    			table="PREFERENCE"
    			cascade="all"
    		>
    			<key column="PRO_ID"/>
    			<many-to-many column="RTT_ID" class="Entite"/>
    		</set>
    		<set
    			name="utilisateurs"
    			table="RESERVATION"
    			cascade="all"
    		>
    			<key column="PRO_ID"/>
    			<many-to-many column="UTL_ID" class="Utilisateur"/>
    		</set>
     
     
    	</class>	
    </hibernate-mapping>
    voila mon code qui pose probleme :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
     
    public class ProfilDAO extends BaseProfilDAO {
     
    	/**
             * Default constructor.  Can be used in place of getInstance()
             */
    	public ProfilDAO () {}
     
    	public Profil getByCollaborateurId(Integer id, Session session){
    		ProfilDAO.initialize();
    		Profil profil = (Profil)ProfilDAO.getInstance().getQuery("from Profil profil fetch all properties where profil.collaborateur.id =:id",session).setInteger("id",id).uniqueResult();
     
    		//Profil profil = (Profil)ProfilDAO.getInstance().getQuery("from Profil profil inner join fetch profil.collaborateur where profil.collaborateur.id =:id",session).setInteger("id",id).uniqueResult();
     
    		return profil;
    	}
     
    	public static void main(String[] args){
     
    		Session session = HibernateUtil.currentSession();
    		Transaction tx = session.beginTransaction();		
    		Profil profil = ProfilDAO.getInstance().getByCollaborateurId(Integer.valueOf(24),session);
    		tx.commit();
    		session.close();
     
    		System.out.println(profil.toString());
     
     
    		System.out.println(profil.getCollaborateur().getNom());
     
     
     
    	}
     
    }

  2. #2
    Membre éclairé Avatar de agougeon
    Inscrit en
    Mai 2005
    Messages
    253
    Détails du profil
    Informations forums :
    Inscription : Mai 2005
    Messages : 253
    Par défaut
    j'ai résolu mon pb avec :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    		ProfilDAO.initialize();
    		//Profil profil = (Profil)ProfilDAO.getInstance().getQuery("from Profil profil left join fetch profil.collaborateur join fetch profil.situation join fetch profil.client join fetch profil.fonction join fetch profil.societe where profil.collaborateur.id =:id",session).setInteger("id",id).uniqueResult();
    		Criteria crit=session.createCriteria(Profil.class);
    		//Profil profil = (Profil)ProfilDAO.getInstance().getQuery("from Profil profil inner join fetch profil.collaborateur where profil.collaborateur.id =:id",session).setInteger("id",id).uniqueResult();
    		crit.add(Expression.eq("collaborateur.id",id));
    		Profil profil = (Profil)crit.uniqueResult();
    		return profil;

  3. #3
    Membre éclairé
    Profil pro
    ingenieur
    Inscrit en
    Avril 2002
    Messages
    207
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : ingenieur

    Informations forums :
    Inscription : Avril 2002
    Messages : 207
    Par défaut
    Merci infiniment.
    Je suis sur une appli 3 couches :
    Hibernate + webService (xfire) + Ihm (JSF).
    J'ai eu le meme pb que toi ???
    J'ai appliqué ta solution !!! et Miracle, ca marche ... ???
    Mais je ne comprends par pourquoi ?.???? ? ?? ?? ?

    Moi je faisais un get(...) que j'ai remplacé par le Criteria....etc...

    en ttout cas, Merci, il est 20h24 ca fait du bien quand ca marche....


+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 3
    Dernier message: 19/01/2006, 14h49
  2. [Hibernate] Exception bizarre NoSuchElementException
    Par lilou77 dans le forum Hibernate
    Réponses: 3
    Dernier message: 17/01/2006, 15h44
  3. [Hibernate] exception entre MySQL et MS SQL
    Par lilou77 dans le forum Hibernate
    Réponses: 7
    Dernier message: 13/01/2006, 11h52
  4. [Hibernate exception]
    Par agougeon dans le forum Hibernate
    Réponses: 7
    Dernier message: 08/01/2006, 17h36
  5. Réponses: 5
    Dernier message: 25/05/2005, 21h16

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo