-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: session.flush => net.sf.hibernate.HibernateException
PostPosted: Thu Mar 19, 2009 12:22 pm 
Newbie

Joined: Wed Jan 21, 2009 4:22 am
Posts: 2
The session.flush java code return a net.sf.hibernate.HibernateException identifier of an instance of fr.gouv.impots.appli.pivotmas.persistance.modeleov.EtatTraitementMdlValeur altered
from fr.gouv.impots.appli.pivotmas.persistance.modeleov.EtatTraitementMdlValeur@2585e
to fr.gouv.impots.appli.pivotmas.persistance.modeleov.EtatTraitementMdlValeur@2585e

This error only occured in the modification operation. Here are the details of my configuration and execution :

Hibernate version:
2.0

Mapping documents:

No need in this case. The mapping works on creation and get operation. The only operation which failed is the modification

Code between sessionFactory.openSession() and session.close():

Code:
Session session = HibernateUtil.currentSession();
depot = restituerDepotById(session, requete.getIdDepot()); //Works fine

Iterator iterat = depot.getListeSectionsDepot().iterator();
while (iterat.hasNext())
            {
                SectionMdlValeur sectionMdlValeur = (SectionMdlValeur) iterat.next();
                boolean aModifier = ((requete.getIdSection() != null) ? (sectionMdlValeur.getId().equals(requete
                        .getIdSection())) : ((requete.getTypeSection() != null) ? (sectionMdlValeur.getTypeSection()
                            .getCode().equals(requete.getTypeSection())) : true));
                if (aModifier)
                {
                    modifierEtatSection(sectionMdlValeur, requete, session);
                    // Incrementer le Nb de sections modifiees
                    nbSectionsModifiees++;
                }
            }

            session.save(depot);
            session.flush();


Full stack trace of exception that occurs:

Stacktrace :

Quote:
net.sf.hibernate.HibernateException: identifier of an instance of fr.gouv.impots.appli.pivotmas.persistance.modeleov.EtatTraitementMdlValeur altered from fr.gouv.impots.appli.pivotmas.persistance.modeleov.EtatTraitementMdlValeur@11edceb to fr.gouv.impots.appli.pivotmas.persistance.modeleov.EtatTraitementMdlValeur@11edceb
at net.sf.hibernate.impl.SessionImpl.checkId(SessionImpl.java:2670)
at net.sf.hibernate.impl.SessionImpl.flushEntity(SessionImpl.java:2493)
at net.sf.hibernate.impl.SessionImpl.flushEntities(SessionImpl.java:2486)
at net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2281)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2260)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at fr.gouv.impots.appli.pivotmas.persistance.DepotDaoEntite_ModifierDepotTest.testModifierEtat(DepotDaoEntite_ModifierDepotTest.java:207)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)


database :
Oracle 10.2.0.3.0

The generated SQL (show_sql=true):

Long and boring, the code line where the exception occured doesn't show generated sql. But just in cas, here is the previous generated code :

The only interesting thing to me is that there is no insert or alter or update statement :

Quote:
Hibernate: select listeetats0_.ID_SECTION as ID_SECTION__, listeetats0_.ID_REFERENCE_CONSOMMATEUR as ID_REFER2___, listeetats0_.ID_SECTION as ID_SECTION0_, listeetats0_.ID_REFERENCE_CONSOMMATEUR as ID_REFER2_0_, listeetats0_.ID_REFERENCE_ETAT_TRAITEMENT as ID_REFER3_0_, listeetats0_.HORODATAGE as HORODATAGE0_, listeetats0_.DATE_PREMIERE_ANO as DATE_PRE5_0_ from t_etat_traitement listeetats0_ where listeetats0_.ID_SECTION=?
Hibernate: select this.ID_REFERENCE as ID_REFER1_0_, this.CODE as CODE0_, this.LIBELLE as LIBELLE0_, this.NATURE as NATURE0_ from t_reference this where this.NATURE=?
Hibernate: select this.ID_REFERENCE as ID_REFER1_0_, this.CODE as CODE0_, this.LIBELLE as LIBELLE0_, this.NATURE as NATURE0_ from t_reference this where this.NATURE=?


Thank you for reading!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 19, 2009 1:12 pm 
Beginner
Beginner

Joined: Wed Oct 03, 2007 4:10 am
Posts: 46
This is what I understand from your code:

It seems that you modify the id property of an fr.gouv.impots.appli.pivotmas.persistance.modeleov.EtatTraitementMdlValeur instance somewhere between getting the instance from db.

and session.flush(). You have to isolate the error in a simpler test case

and to post the mapping for EtatTraitementMdlValeur and the methods

involved in the modif of the instance EtatTraitementMdlValeur


in order to help.


But first of all comment out the line

modifierEtatSection(sectionMdlValeur, requete, session);

and see if you still get error.

Good luck.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 20, 2009 6:56 am 
Newbie

Joined: Wed Jan 21, 2009 4:22 am
Posts: 2
Good check indeed, there isn't any EtatTraitement in DB before the call of this method. That's why I'm astonished about this exception! Here is the code you asked me :

Code:
   

private void modifierEtatSection(SectionMdlValeur section,
                                     ModificationEtatRequeteValeur requete,
                                     Session session) throws HibernateException, TechniqueErreur
    {
        // Passage en "attente"
        if (requete.getCodeEtat().equals(ConstantesValeur.CODE_ETAT_ATTENTE))
        {
            supprimerEtatSection(section, requete.getIdService());
        }
        else
        {
            changerEtatSection(section, requete, session);
        }
    }

which call this one :

private void changerEtatSection(SectionMdlValeur section,
                                    ModificationEtatRequeteValeur requete,
                                    Session session) throws HibernateException, TechniqueErreur
    {
        Iterator itEtats = section.getListeEtatsTraitements().iterator();
        EtatTraitementMdlValeur etatTraitement = null;
        ReferenceMdlValeur refEtatTraitement = RestituerListesValeursRefDaoEntite.getInstance().getReference(
                requete.getCodeEtat(), RestituerListesValeursRefDaoEntite.ETAT_TRAITEMENT);
        boolean trouve = false;

        long idAnomalie = 0L;
        while (itEtats.hasNext() && !trouve)
        {
            etatTraitement = (EtatTraitementMdlValeur) itEtats.next();
            if (etatTraitement.getConsommateur().getCode().equals(requete.getIdService()))
            {
                // Recup du max des id pour cet etat de traitement
                Iterator itAnomalies = etatTraitement.getListeAnomalies().iterator();
                while (itAnomalies.hasNext())
                {
                    long idTemp = ((AnomalieMdlValeur) itAnomalies.next()).getId().longValue();
                    idAnomalie = (idAnomalie > idTemp ? idAnomalie : idTemp);
                }
                // Suppression des anomalies de l'etat
                etatTraitement.getListeAnomalies().clear();
                etatTraitement.setHorodatage(new GregorianCalendar());
                trouve = true;
            }
        }

        // Si l'etat n'a été trouvé en base , l'ajouter
        if (!trouve)
        {
            etatTraitement = new EtatTraitementMdlValeur();
            etatTraitement.setTheSectionMdlValeur(section);
            etatTraitement.setConsommateur(RestituerListesValeursRefDaoEntite.getInstance().getReference(
                    requete.getIdService(), RestituerListesValeursRefDaoEntite.CONSOMMATEUR));
            etatTraitement.setHorodatage(new GregorianCalendar());
            if (requete.getCodeEtat().equals(ConstantesValeur.CODE_ETAT_ANOMALIE))
            {
                etatTraitement.setDatePremiereAno(etatTraitement.getHorodatage());
            }
            section.addTolisteEtatsTraitements(etatTraitement);
        }

        etatTraitement.setEtatTraitement(refEtatTraitement);

        // Ajout des anomalies
        if (requete.getListeCodesAnomalies() != null)
        {
            for (int i = 0; i < requete.getListeCodesAnomalies().length; i++)
            {
                AnomalieMdlValeur anomalie = new AnomalieMdlValeur();
                anomalie.setTheEtatTraitementMdlValeur(etatTraitement);
                anomalie.setAnoTraitement(RestituerListesValeursRefDaoEntite.getInstance().getReference(
                        requete.getListeCodesAnomalies(i).getCode(),
                        RestituerListesValeursRefDaoEntite.ANOMALIE_TRAITEMENT));
                anomalie.setId(new Long(++idAnomalie));
                etatTraitement.addTolisteAnomalies(anomalie);
            }
        }
    }


Mapping :

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping package="fr.gouv.impots.appli.pivotmas.persistance.modeleov">
   <class
      name="EtatTraitementMdlValeur"
      table="t_etat_traitement"
   >

      <composite-id unsaved-value="any">
         <key-many-to-one name="theSectionMdlValeur"
                      class="SectionMdlValeur"
                      column="ID_SECTION"/>
         <key-many-to-one name="consommateur"
                      class="ReferenceMdlValeur"
                      column="ID_REFERENCE_CONSOMMATEUR"/>
      </composite-id>

      <many-to-one name="etatTraitement" class="ReferenceMdlValeur" column="ID_REFERENCE_ETAT_TRAITEMENT" outer-join="false"/>

      <property
         name="Horodatage"
         column="HORODATAGE"
         type="java.util.Calendar"
         not-null="false"
         length="10"
      />
      <property
         name="DatePremiereAno"
         column="DATE_PREMIERE_ANO"
         type="java.util.Calendar"
         not-null="false"
         length="10"
      />

      <set name="listeAnomalies" cascade="all-delete-orphan" inverse="true" lazy="true">
          <key>
             <column name="ID_SECTION"/>
             <column name="ID_REFERENCE_CONSOMMATEUR"/>
          </key>
          <one-to-many class="AnomalieMdlValeur"/>
      </set>
   </class>
</hibernate-mapping>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.