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] Illegal attempt to associate a collection with..


Sujet :

Hibernate Java

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Décembre 2005
    Messages
    76
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2005
    Messages : 76
    Points : 49
    Points
    49
    Par défaut [HIBERNATE] Illegal attempt to associate a collection with..
    Bonjour,
    je travaille avec hibernate 3.1, eclipse 3.1, mysql5 et java5.

    J'ai une méthode de suppression en base, qui doit supprimer un objet et toutes ses dépendances, c'est à dire une identite, et puis son adresse, son infraction, l'adresse de l'infraction :

    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
    	public static void supprimerIdentite(Integer ididentite) {
    		_RootDAO.initialize();
    		Session session = HibernateUtil.getSessionFactory().openSession();
    		Transaction tx = session.beginTransaction();
    		tx.begin();
    		try {
    			InfractionDAO ilsDAO = new InfractionDAO();
    			AdresseDAO adDAO = new AdresseDAO();
     
    			//adresse de domicile
    			session.createQuery("delete from Adresse where IDENTITE_ID_IDENTITE = :idIdentite ").setInteger("idIdentite", ididentite).executeUpdate();
     
    			//infractions (connexes)
    			Infraction inf = (Infraction)session.createQuery("from Infraction where IDENTITE_ID_IDENTITE = :idIdentite").
    			setInteger("idIdentite",ididentite ).uniqueResult();
     
    			if (inf != null) {
    				//adresse infraction
    				session.createQuery("delete from Adresse where INFRACTION_ID_ILS = :idInf ").setInteger("idInf", inf.getIdIls()).executeUpdate();
    				ilsDAO.delete(inf);	
    			}
    			//identite (alias et surnom)
    			IdentiteDAO idDAO = new IdentiteDAO();
    			idDAO.delete(ididentite);
     
    			tx.commit();
    			session.close();
    		} catch (HibernateException e) {
    			tx.rollback();
    			session.close();
    			e.printStackTrace();
    		}
    		catch (Exception e) {
    			tx.rollback();
    			session.close();
    			e.printStackTrace();
    		}
    	}
    Hibernate me renvoie l'erreur 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
    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
    Hibernate: 
        delete 
        from
            adresse 
        where
            INFRACTION_ID_ILS=?
    org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
     at org.hibernate.collection.AbstractPersistentCollection.setCurrentSession(AbstractPersistentCollection.java:410)
     at org.hibernate.event.def.OnUpdateVisitor.processCollection(OnUpdateVisitor.java:40)
     at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:101)
     at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:61)
     at org.hibernate.event.def.AbstractVisitor.processEntityPropertyValues(AbstractVisitor.java:55)
     at org.hibernate.event.def.AbstractVisitor.process(AbstractVisitor.java:123)
     at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:72)
     at org.hibernate.impl.SessionImpl.fireDelete(SessionImpl.java:764)
     at org.hibernate.impl.SessionImpl.delete(SessionImpl.java:743)
     at com.osiris.hibernate.beans.base._BaseRootDAO.delete(_BaseRootDAO.java:761)
     at com.osiris.hibernate.beans.base._BaseRootDAO$5.run(_BaseRootDAO.java:749)
     at com.osiris.hibernate.beans.base._BaseRootDAO.run(_BaseRootDAO.java:788)
     at com.osiris.hibernate.beans.base._BaseRootDAO.delete(_BaseRootDAO.java:746)
     at com.osiris.hibernate.beans.base.BaseInfractionDAO.delete(BaseInfractionDAO.java:194)
     at com.osiris.services.specifique.SupprimerService.supprimerIdentite(SupprimerService.java:56)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
     at java.lang.reflect.Method.invoke(Unknown Source)
     at flashgateway.adapter.java.JavaAdapter.invokeFunction(JavaAdapter.java:55)
     at flashgateway.filter.AdapterFilter.invoke(AdapterFilter.java:117)
     at flashgateway.filter.MessageSecurityFilter.invoke(MessageSecurityFilter.java:144)
     at flashgateway.filter.ServiceNameFilter.invoke(ServiceNameFilter.java:101)
     at flashgateway.filter.EnvelopeFilter.invoke(EnvelopeFilter.java:102)
     at flashgateway.filter.SessionFilter.invoke(SessionFilter.java:28)
     at flashgateway.filter.LicenseFilter.invoke(LicenseFilter.java:57)
     at flashgateway.filter.ErrorFilter.invoke(ErrorFilter.java:39)
     at flashgateway.filter.LogFilter.invoke(LogFilter.java:46)
     at flashgateway.filter.BatchProcessFilter.invoke(BatchProcessFilter.java:63)
     at flashgateway.filter.PacketSecurityFilter.invoke(PacketSecurityFilter.java:68)
     at flashgateway.filter.DebugFilter.invoke(DebugFilter.java:38)
     at flashgateway.filter.SerializationFilter.invoke(SerializationFilter.java:89)
     at flashgateway.Gateway.invoke(Gateway.java:217)
     at flashgateway.controller.GatewayServlet.service(GatewayServlet.java:69)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
     at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:868)
     at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:663)
     at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
     at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
     at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
     at java.lang.Thread.run(Unknown Source)

    N'est-il pas possible d'avoir plusieurs opérations dans la même transaction ??? Oua lors, dois-je merger certains objets entre les requêtes ??

  2. #2
    Membre du Club
    Profil pro
    Inscrit en
    Décembre 2005
    Messages
    76
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2005
    Messages : 76
    Points : 49
    Points
    49
    Par défaut
    J'ai remplacé le code :

    par un simple :


    et ça fonctionne...Je ne comprends pas pourquoi.

  3. #3
    Membre averti
    Inscrit en
    Août 2005
    Messages
    352
    Détails du profil
    Informations forums :
    Inscription : Août 2005
    Messages : 352
    Points : 427
    Points
    427
    Par défaut
    Ca a certainement à voir avec le code de ton DAO...

  4. #4
    Membre averti
    Profil pro
    Inscrit en
    Juillet 2005
    Messages
    274
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 274
    Points : 307
    Points
    307
    Par défaut
    Bonjour,

    ton erreur est due à l'utilisation de sessions différentes au sein de ta transaction.

    La méthode ilsDAO.delete(inf) utilise sa propre session et non pas celle que tu as récupérer pour débuter ta transaction.

    Il y a plusieurs versions des méthodes générées par le plugin HibernateSynchronizer.

    Il doit exister une méthode ilsDAO.delete(inf, session), session étant la session Hibernate que tu recupère dans le début de ton code; C'est cette version qu'il faut utiliser au sein d'une transaction avec plusieurs opérations.

  5. #5
    Membre du Club
    Profil pro
    Inscrit en
    Décembre 2005
    Messages
    76
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2005
    Messages : 76
    Points : 49
    Points
    49
    Par défaut
    Merci, c'est simplement limpide.

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

Discussions similaires

  1. Réponses: 13
    Dernier message: 01/03/2011, 17h12
  2. Réponses: 1
    Dernier message: 30/09/2008, 18h07
  3. Réponses: 2
    Dernier message: 13/10/2006, 17h38
  4. Réponses: 4
    Dernier message: 20/07/2006, 17h26

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