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 :

[Spring][Hibernate]illegal access to loading collection


Sujet :

Hibernate Java

  1. #1
    Candidat au Club
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    2
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2006
    Messages : 2
    Points : 2
    Points
    2
    Par défaut [Spring][Hibernate]illegal access to loading collection
    Bonjour,
    Je bloque actuellement sur l'accès aux données dans un projet de développement Spring/Hibernate. L'application sera lancée directement en ligne de commande.

    L'environnement du test qui ne passe pas est le suivant :

    applicationContext.xml :
    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
     
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    	<property name="configLocation">
    		<value>classpath:hibernate.cfg.xml</value>
    	</property>
    	<property name="mappingResources">
    		<list>
    			<value>/test/Message.hbm.xml</value>
    			<value>/test/object.hbm.xml</value>
    		</list>
    	</property>
    </bean>
     
    <bean name="hibernateInterceptor" class="org.springframework.orm.hibernate3.HibernateInterceptor">
    	<property name="sessionFactory">
    		<ref bean="sessionFactory" />
    	</property>
    </bean>
     
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    	<property name="sessionFactory">
    		<ref bean="sessionFactory" />
    	</property>
    </bean>
     
    <bean id="objectDao" class="object.dao.objectDaoImpl">
    	<property name="sessionFactory">
    		<ref bean="sessionFactory" />
    	</property>
    </bean>
     
    <bean id="objectDao" class="org.springframework.aop.framework.ProxyFactoryBean">
    	<property name="target"><ref bean="objectDaoTarget"/></property>
    	<property name="proxyInterfaces">
    		<value>dao.object.objectDao</value>
    	</property>
    	<property name="interceptorNames">
    		<list><value>hibernateInterceptor</value></list>
    	</property>
    </bean>
    Mapping de object :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
    <hibernate-mapping>
    	<class name="data.object.objectBean"
    		table="object">
    		<id name="objectId" type="long" column="OBJECT_ID">
    			<generator class="increment"></generator>
    		</id>
    		<set name="messages" cascade="all">
    			<key column="OBJECT_ID"></key>
    			<one-to-many class="data.message.MessageBean"/>
     
    		</set>
    	</class>
    </hibernate-mapping>
    Le mapping de message :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
    <hibernate-mapping>
    	<class name="data.message.MessageBean" table="Message">
     
    		<id name="messageId" type="long" column="MESSAGE_ID" >
    			<generator class="increment"></generator>
    		</id>
     
    		<many-to-one name="object" class="data.object.objectBean"
    			column="OBJECT_ID">
    		</many-to-one>
    	</class>
    </hibernate-mapping>
    Le code de la DAO :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    public class objectDaoImpl extends HibernateDaoSupport implements objectDao {
     
    	public int getMessagesNumber(Long objectId) throws ObjectNotFoundException {
    		objectBean object = (objectBean)getHibernateTemplate().get(objectBean.class, objectId) ;
    		if (object==null) {
    			logger.error("L'objet d'identifiant "+objectId+" n'a pas été trouvé dans la base.") ;
    			throw new ObjectNotFoundException("L'objet d'identifiant "+objectId+" n'a pas été trouvé dans la base.") ;
    		}
     		Set messages = object.getMessage() ;
    		return messages.size();
    	}
    Mon code de test fait, tout simplement, un appel à objectDao.getMessagesNumber(..).
    Le test leve une exception :
    org.hibernate.LazyInitializationException: illegal access to loading collection

    Pourtant j'utilise bien un ProxyFactoryBean qui devrait spécifier qu'une session doit etre ouverte en début de méthode de objectDao puis fermée en fin de méthode.

    Autre point bizarre, si je définis le set "messages" en lazy="false", il se passe la meme chose. A la récupération de l'objet.

    Je crois avoir fouillé entierement ce forum sur le question. Rien ne peut résoudre mon probleme.

    Quelqu'un aurait une idée ?
    Merci

    Y

  2. #2
    Candidat au Club
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    2
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2006
    Messages : 2
    Points : 2
    Points
    2
    Par défaut Résolu
    L'object persistant object contenait une méthode qui ne passait pas la couche Hibernate.

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    93
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 93
    Points : 46
    Points
    46
    Par défaut
    Bonjour !!

    Bon je sais je fais un petit up, mais est ce que toi (si tu passes encore par ici ) ou un autre peut m'expliquer ce que tu entends par qui ne passait pas la couche Hibernate ??

    Je te remercie, ou celui qui me répondra, mais ca me rendrait un ENORME service , vu que j'ai le soucis ...

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

Discussions similaires

  1. Hibernate / illegal access to loading collection
    Par jaudouy dans le forum Accès aux données
    Réponses: 3
    Dernier message: 13/04/2010, 11h58
  2. illegal access to loading collection
    Par <romain/> dans le forum Hibernate
    Réponses: 0
    Dernier message: 14/04/2009, 18h14
  3. Réponses: 4
    Dernier message: 11/04/2008, 12h12
  4. Spring hibernate lazy loading
    Par mauroyb0 dans le forum Hibernate
    Réponses: 6
    Dernier message: 09/05/2007, 12h14
  5. [HIBERNATE] Illegal attempt to associate a collection with..
    Par PamelaGeek dans le forum Hibernate
    Réponses: 4
    Dernier message: 02/03/2006, 11h09

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