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

Spring Java Discussion :

Problème StaleStateException avec la méthode saveOrUpdate()


Sujet :

Spring Java

  1. #1
    Futur Membre du Club
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    8
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2007
    Messages : 8
    Points : 5
    Points
    5
    Par défaut Problème StaleStateException avec la méthode saveOrUpdate()
    Bonjour;

    Je developpe actuellement ma premièreapplication basée sur Spring et j'ai commencé la partie persistance.
    ça va faire trois jours que je cherche à résoudre une exception :
    Pour mes tests unitaires, j'hérite de la classe AbstractTransactionalDataSourceSpringContextTests.

    voici un bout de ma classe de test
    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 class TestUtilisateurDao extends AbstractTransactionalDataSourceSpringContextTests {
     
            UtilisateurDao  utilisateurDao;	
     
            ...
            ...
     
      	public void testSauvegarderIntervenant() {
     
    		//Start of user code sauvegarderIntervenant 
    		utilisateurDao.sauvegarderIntervenant(intervenant1);
    		logger.debug("XXXXXXXXXXXXXXXXXXXXXXXXX"+countRowsInTable("intervenant"));
     
                    utilisateurDao.sauvegarderIntervenant(intervenant2);
    		utilisateurDao.sauvegarderIntervenant(intervenant3);
     
    		Intervenant intervenantCharge = utilisateurDao.chargerIntervenant(intervenant1.getIdIntervenant());
    		logger.debug("XXXXXXXXXXXXXXXXXXXXXXXXX"+jdbcTemplate.queryForInt("select count(*) from intervenant"));
    		assertTrue( jdbcTemplate.queryForInt("select count(*) from intervenant")== 3);
     
     
    	}
     
            ...
            ...
     
    protected void onSetUpBeforeTransaction() throws Exception {
    		super.onSetUpBeforeTransaction();
     
    		intervenant1 = new Intervenant(1500,"brian", "youss", "brain.youss@sii.fr", "chef","0231228547","0231228547","GRT","interne",true);
     
            	intervenant2 = new Intervenant(1501,"brian", "michel", "jeanMich@sii.fr", "ingenieur","0231247896","0231232547","JMM","interne",true);
     
                    intervenant3 = new Intervenant(1502,"rene", "bernard", "reneBernard@sii.fr", "ingenieur","0231896547","0231998984","RBR","externe",true);
            }
     
    }

    Voici l'implémentation ma fonction sauvegarderIntervenant ;

    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
     
    	public void sauvegarderIntervenant(Intervenant intervenant) throws DataAccessException {
    		log.debug("Debut de la fonction sauvegarderIntervenant()");
     
    		getHibernateTemplate().saveOrUpdate(intervenant);	
    		//LIGNE QUI NE BUGGE PAS		
    		log.debug(((Intervenant) getHibernateTemplate().load(intervenant.getClass(), intervenant.getIdIntervenant())).getEmail());
     
    		//pour vérifier si ma table possede bien un enregistrement
                    Iterator results = getSession().createQuery("select int from Intervenant int").list().iterator(); //LIGNE QUI BUGGE
    		int i = 0;
    		while ( results.hasNext() ) {
    			i++;
    		}
     
    		log.debug("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF " + i);
    		log.debug("Fin de la fonction sauvegarderIntervenant()");
    	}
    La LIGNE QUI NE BUGGE PAS m'affiche bien l'email de l'intervenant que je viens d'enregistrer
    maislors de l'exécution de la LIGNE QUI BUGGE, je reçois l'exception suivante :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    org.hibernate.StaleStateException: Batch update returned unexpected row count from update: 0 actual row count: 0 expected: 1
    	at org.hibernate.jdbc.BatchingBatcher.checkRowCount(BatchingBatcher.java:93)
    	at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:79)
    	at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
    	at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:195)
    Il semblerait donc que mon appel à la méthode saveOrUpdate() provoque une inconsistance
    de ma base de donnée mais je ne sais pas du tout comment résoudre ce problème.

    Quelqu'un aurait t'il la réponse qui me ferait gagner tellement de temps ?
    (du moins qui arrêterait de m'en faire perdre)

    Siouplait ?

    Dans un soucis de complétude, je joins aussi mon mapping hibernate de la classe Intervenant
    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
     
     
    <hibernate-mapping auto-import="true" default-lazy="true">
     
    	<class name="domaine.utilisateur.Intervenant" table="intervenant">
    		<id name="idIntervenant" column="idIntervenant" type="long">
    			<generator class="identity"/>
    		</id>
    		<property name="nom" column="nom" type="string"/>
    		<property name="prenom" column="prenom" type="string"/>
    		<property name="email" column="email" type="string"/>
    		<property name="fonction" column="fonction" type="string"/>
    		<property name="numTel" column="numTel" type="string"/>
    		<property name="numFax" column="numFax" type="string"/>
    		<property name="trigramme" column="trigramme" type="string"/>
    		<property name="type" column="type" type="string"/>
    		<property name="actif" column="actif" type="boolean"/>
    	</class>
     
     
     
    </hibernate-mapping>

    Merci d'avance à la bonne âme qui aura le courage de se pencher sur mon problème !

  2. #2
    Membre chevronné
    Homme Profil pro
    Directeur technique
    Inscrit en
    Janvier 2007
    Messages
    1 348
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Directeur technique

    Informations forums :
    Inscription : Janvier 2007
    Messages : 1 348
    Points : 1 787
    Points
    1 787
    Par défaut
    Ce n'est pas l'intégralité de ta stack trace là si ?
    Sinon tu peux donner un peu plus le code entre le constructeur et la sauvegarde ?

  3. #3
    Futur Membre du Club
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    8
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2007
    Messages : 8
    Points : 5
    Points
    5
    Par défaut
    Merci de ta réponse rapide !

    Effectivement, j'ai un peu scindé la stacktrace, j'aurais p'tet pas dû :
    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
     
    org.hibernate.StaleStateException: Batch update returned unexpected row count from update: 0 actual row count: 0 expected: 1
    	at org.hibernate.jdbc.BatchingBatcher.checkRowCount(BatchingBatcher.java:93)
    	at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:79)
    	at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
    	at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:195)
    	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
    	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
    	at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
    	at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:41)
    	at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:954)
    	at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1099)
    	at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
    	at hibernateDAO.implementations.UtilisateurDaoImpl.sauvegarderIntervenant(UtilisateurDaoImpl.java:148)
    	at hibernateDAO.tests.TestUtilisateurDao.testSauvegarderIntervenant(TestUtilisateurDao.java:160)
    	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 junit.framework.TestCase.runTest(TestCase.java:154)
    	at junit.framework.TestCase.runBare(TestCase.java:127)
    	at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:69)
    	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:128)
    	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)

    Euh sinon je ne pense pas qu'il est beaucoup de code intéressant entre le constructeur et la sauvegarde, mais bon je mets la classe complète à tout hasard :


    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
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
     
     
    public class TestUtilisateurDao extends AbstractTransactionalDataSourceSpringContextTests {
     
    	UtilisateurDao  utilisateurDao;	
     
    	//Start of user code membres de la classe
     
    	ProjetDao projetDao;
     
    	private Societe societe1;
    	private Societe societe2;
    	private Intervenant intervenant1;
    	private Intervenant intervenant2;
    	private Intervenant intervenant3;
    	private Projet projet1;
    	private Projet projet2;
    	private Projet projet3;
    	private Acces acces1;
    	private Acces acces2;
    	private Acces acces3;
    	private Acces acces4;
    	private Acces acces5;
    	private Action action1;
    	private Action action2;
    	private Action action3;
    	private Action action4;
    	private Action action5;
    	private Action action6;
    	private Action action7;
    	private Risque risque1;
    	private Risque risque2;
    	private Risque risque3;
    	private Risque risque4;
    	private Risque risque5;
    	private Risque risque6;
    	private Risque risque7;
    	private Risque risque8;
    	private Risque risque9;
    	private Admin admin1;
    	private Admin admin2;
     
    	private Habilitation habilitation1;
     
    	private Habilitation habilitation2;	
     
    	//End of user code membres de la classe
     
    	public void testSauvegarderAcces() {
     
    		//Start of user code sauvegarderAcces 
    		utilisateurDao.sauvegarderAcces(acces1);
     
    		Acces accesCharge = utilisateurDao.chargerAcces(acces1.getLogin());
     
    		assertTrue(accesCharge.equals(acces1));
    		//End of user code sauvegarderAcces
     
    	}
     
     
    	public void testRechercheAccesParIdIntervenant() {
     
    		//Start of user code rechercheAccesParIdIntervenant 
    		utilisateurDao.sauvegarderIntervenant(intervenant2);  
     
    		assert(utilisateurDao.rechercheAccesParIdIntervenant(intervenant2.getIdIntervenant()) == acces2);
    		//End of user code rechercheAccesParIdIntervenant
     
    	}
     
     
    	public void testChargerAcces() {
     
    		//Start of user code chargerAcces 
    		utilisateurDao.sauvegarderAcces(acces1);
    		Acces accesCharge = utilisateurDao.chargerAcces(acces1.getLogin());
     
    		assert(accesCharge.equals(acces1));
    		//End of user code chargerAcces
     
    	}
     
     
    	public void testSupprimerAcces() {
     
    		//Start of user code supprimerAcces 
    		utilisateurDao.sauvegarderAcces(acces1);
    		Acces accesCharge = utilisateurDao.chargerAcces(acces1.getLogin());
    		assertTrue(accesCharge.equals(acces1));
    		utilisateurDao.supprimerAcces(acces1.getLogin());
     
    		assert(utilisateurDao.chargerAcces(acces1.getLogin())==null);
     
    		//End of user code supprimerAcces
     
    	}
     
     
    	public void testToutLesIntervenants() {
     
    		//Start of user code toutLesIntervenants 
     
    		//utilisateurDao.sauvegarderIntervenant(intervenant1);
    		//utilisateurDao.sauvegarderIntervenant(intervenant2);
    		//utilisateurDao.sauvegarderIntervenant(intervenant3);
    		//jdbcTemplate.execute("insert into intervenant value (1500,\'brian\', \'youss\', \'brain.youss@sii.fr\', \'chef\',\'0231228547\',\'0231228547\',\'GRT\',\'sparadrah\',true,\'interne\',10,\'interne\')");
    		ArrayList<Intervenant> intervenants = (ArrayList<Intervenant>) utilisateurDao.toutLesIntervenants(); 
    		logger.debug("XXXXXXXXXXXXXXXXXXreteerferf");
    		assertTrue(intervenants.size()==1
    				/*intervenants.contains(intervenant1)&&
    				intervenants.contains(intervenant2)&&
    				intervenants.contains(intervenant3)*/);
     
    		//End of user code toutLesIntervenants
     
    	}
     
     
    	public void testRechercheIntervenantsParNomIntervenant() {
     
    		//Start of user code rechercheIntervenantsParNomIntervenant 
    		utilisateurDao.sauvegarderIntervenant(intervenant1);
    		utilisateurDao.sauvegarderIntervenant(intervenant2);
    		ArrayList<Intervenant> intervenants = (ArrayList<Intervenant>) utilisateurDao.rechercheIntervenantsParNomIntervenant(intervenant1.getNom()); 
    		assertTrue(
    				intervenants.contains(intervenant1)&&
    				intervenants.contains(intervenant2));
    		//End of user code rechercheIntervenantsParNomIntervenant
     
    	}
     
     
    	public void testSauvegarderIntervenant() {
     
    		//Start of user code sauvegarderIntervenant 
    		utilisateurDao.sauvegarderIntervenant(intervenant1);
    		logger.debug("XXXXXXXXXXXXXXXXXXXXXXXXX"+countRowsInTable("intervenant"));
    		utilisateurDao.sauvegarderIntervenant(intervenant2);
    		utilisateurDao.sauvegarderIntervenant(intervenant3);
     
    		Intervenant intervenantCharge = utilisateurDao.chargerIntervenant(intervenant1.getIdIntervenant());
    		logger.debug("XXXXXXXXXXXXXXXXXXXXXXXXX"+jdbcTemplate.queryForInt("select count(*) from intervenant"));
    		assertTrue(jdbcTemplate.queryForInt("select count(*) from intervenant")== 3
    				/*intervenantCharge.equals(intervenant1)&&
    					utilisateurDao.chargerAcces(acces1.getLogin()).equals(acces1)
    		*/);
    		//End of user code sauvegarderIntervenant
     
    	}
     
     
    	public void testRechercherIntervenantsInternes() {
     
    		//Start of user code rechercherIntervenantsInternes 
    		utilisateurDao.sauvegarderIntervenant(intervenant1);
    		utilisateurDao.sauvegarderIntervenant(intervenant2);
    		utilisateurDao.sauvegarderIntervenant(intervenant3);
     
    		ArrayList<Intervenant> listeInternes = (ArrayList<Intervenant>) utilisateurDao.rechercherIntervenantsInternes();
    		assertTrue(
    				listeInternes.contains(intervenant1)&&
    				listeInternes.contains(intervenant2));
    		//End of user code rechercherIntervenantsInternes
     
    	}
     
     
    	public void testRechercherIntervenantsParProjet() {
     
    		//Start of user code rechercherIntervenantsParProjet 
    		utilisateurDao.sauvegarderIntervenant(intervenant1);
    		utilisateurDao.sauvegarderIntervenant(intervenant2);
    		utilisateurDao.sauvegarderIntervenant(intervenant3);
    		projetDao.sauvegarderProjet(projet1);
    		projetDao.sauvegarderHabilitation(habilitation1);
    		projetDao.sauvegarderHabilitation(habilitation2);
     
    		ArrayList<Intervenant> listesIntervenants = (ArrayList<Intervenant>) utilisateurDao.rechercherIntervenantsParProjet(projet1.getNumOlga());
     
    		assertTrue(
    				listesIntervenants.contains(intervenant3)&&
    				listesIntervenants.contains(intervenant1)
    				);
    		//End of user code rechercherIntervenantsParProjet
     
    	}
     
     
    	public void testRechercheIntervenantParPrenomNom() {
     
    		//Start of user code rechercheIntervenantParPrenomNom 
     
    		//TODO : le code de la fonction   
    		assertTrue(true);
    		//End of user code rechercheIntervenantParPrenomNom
     
    	}
     
     
    	public void testChargerIntervenant() {
     
    		//Start of user code chargerIntervenant 
     
    		utilisateurDao.sauvegarderIntervenant(intervenant1);
    		utilisateurDao.sauvegarderIntervenant(intervenant2);
    		utilisateurDao.sauvegarderIntervenant(intervenant3);
     
    		Intervenant intervenantCharge = utilisateurDao.chargerIntervenant(intervenant1.getIdIntervenant());
    		logger.debug("XXXXXXXXXXXXXXXXXXXXXXXXX"+utilisateurDao.chargerAcces(acces1.getLogin()).getRole());
    		assertTrue( intervenantCharge.equals(intervenant1)&&
    					utilisateurDao.chargerAcces(acces1.getLogin()).equals(acces1)
    		);  
    		//End of user code chargerIntervenant
     
    	}
     
     
    	public void testSauvegarderAdmin() {
     
    		//Start of user code sauvegarderAdmin 
    		utilisateurDao.sauvegarderAdmin(admin1);
    		utilisateurDao.sauvegarderAdmin(admin2);
     
     
    		Admin adminCharge = utilisateurDao.chargerAdmin(admin1.getIdAdmin());
    		assertTrue( adminCharge.equals(admin1)&&
    					utilisateurDao.chargerAcces(acces4.getLogin()).equals(acces4)
    		);
    		//End of user code sauvegarderAdmin
     
    	}
     
     
     
     
     
    	//Start of user code fonctions membres
    	@Override
    	protected void onSetUpBeforeTransaction() throws Exception {
    		super.onSetUpBeforeTransaction();
    		societe1 = new Societe("tyrex");
    		societe2 = new Societe("Stepmind");	
    		acces1 = new Acces("brianYouss","brianIstheBEst","ras");
    		acces2 = new Acces("jeanMichel","jeanIstheBEst","rasToo");
    		acces3 = new Acces("reneBernard","reneIstheBEst","rasToo");	
    		acces4 = new Acces("admin1","godasse","administrateur systeme");
    		acces5 = new Acces("admin2", "loldsfs","pdg");
     
     
    		intervenant1 = new Intervenant(1500,"brian", "youss", "brain.youss@sii.fr", "chef","0231228547","0231228547",acces1,societe1,"GRT","interne",true);
    		intervenant2 = new Intervenant(1501,"brian", "michel", "jeanMich@sii.fr", "ingenieur","0231247896","0231232547",acces2,societe1,"JMM","interne",true);
    		intervenant3 = new Intervenant(1502,"rene", "bernard", "reneBernard@sii.fr", "ingenieur","0231896547","0231998984",acces3,societe2,"RBR","externe",true);
     
    		admin1 = new Admin("Fontaine", "Benjamin","benji.fontaine@gmail.com", acces4,5000);
    		admin2 = new Admin("Wemaere", "François","francois.wemaere@gmail.com", acces5,5001);
     
    		projet1 = new Projet("toto",3000,societe1,"Externe SII",intervenant1,10);
    		projet2 = new Projet("titi",3300,societe1,"Interne SII",intervenant2,10);
    		projet3 = new Projet("tutu",3600,societe2,"Interne SII",intervenant3,10);
     
    		habilitation1 = new Habilitation(7542);
    		habilitation1.setIntervenant(intervenant1);
    		habilitation1.setProjet(projet1);
    		habilitation2 = new Habilitation(7541);
    		habilitation1.setIntervenant(intervenant3);
    		habilitation1.setProjet(projet1);	
     
    		action1 = new Action();
    		action1.setIdAction(1520);
    		action1.setDateCreation(new DateTime());
    		action1.setDateEcheance(new DateTime().plusDays(14));
    		action1.setIntituleAction("TrucBidule");
    		action1.setCreateur(intervenant1);
    		action1.setEtat("enCours");
    		action1.setImportance("superImportante");
    		action1.setOrigine("revueRisque666");
    		//action1.setProjet(projet1);
    		action1.setVisibiliteClient(true);
    		action1.setResponsable(intervenant1);
    		action2 = new Action("revueCodeProjetTiti",new DateTime().plusDays(30),intervenant1,"important","enCours","revueRisque543",false,intervenant1, new DateTime().plusDays(10),10001);
    		action3 = new Action("truc",new DateTime().plusDays(60),intervenant1,"anecdotique","terminee","revueRisque54",true,intervenant3, new DateTime().plusDays(7),10002);
    		action4 = new Action("action4",new DateTime().plusDays(30),intervenant2,"rasant","fini","revueRisque10",true,intervenant1, new DateTime().plusDays(1),10003);
    		action5 = new Action("action5",new DateTime().plusDays(40),intervenant1,"important","enCours","revueRisque15",false,intervenant3, new DateTime().plusDays(2),10004);
    		action6 = new Action("action6",new DateTime().plusDays(50),intervenant3,"important","enCours","revueRisque20",true,intervenant3, new DateTime().plusDays(3),10005);
    		action7 = new Action("action7",new DateTime().plusDays(60),intervenant1,"important","fini","revueRisque25",false,intervenant2, new DateTime().plusDays(4),10006);
     
     
    	}
     
     
     
    	//accesseur utilise par Spring
    	public void setProjetDao( ProjetDao projetDao){
    		this.projetDao = projetDao;
    	}
     
    	//End of user code fonctions membres
     
    	//accesseur utilise par Spring
    	public void setUtilisateurDao( UtilisateurDao utilisateurDao){
    		this.utilisateurDao = utilisateurDao;
    	}
     
    	protected String[] getConfigLocations() {
    		return new String[] { "classpath:ApplicationContext-Hibernate.xml",
    							  "classpath:ApplicationContext-Dao.xml" };
    	}

  4. #4
    Membre chevronné
    Homme Profil pro
    Directeur technique
    Inscrit en
    Janvier 2007
    Messages
    1 348
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Directeur technique

    Informations forums :
    Inscription : Janvier 2007
    Messages : 1 348
    Points : 1 787
    Points
    1 787
    Par défaut
    La première chose c'est que le problème vient de ton saveOrUpdate. En effet, le fait de faire un select provoque le flush de la session et c'est pour cela que le problème n'apparaît que là.
    Pourrais-tu donner le constructeur de ta classe Intervenant ainsi que le log hibernate d'exécution ?

  5. #5
    Futur Membre du Club
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    8
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2007
    Messages : 8
    Points : 5
    Points
    5
    Par défaut
    J'ai placé le log d'exécution (en version zippé pour la version DEBUG et en txt pour la version INFO) en pièce jointe du post parce qu'il est un peu long.


    Et le constructeur de ma classe Intervenant :

    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
     
    public class Intervenant implements Serializable{
     
    	private static final long serialVersionUID = 1L;
     
    	private long idIntervenant ;	
    	private String nom ;	
    	private String prenom ;	
    	private String email ;	
    	private String fonction ;	
    	private String numTel ;	
    	private String numFax ;	
    	private String trigramme ;	
    	private String type ;	
    	private boolean actif ;	
     
     
    	private Societe societe; 
     
    	private Acces acces;
     
    	private List<Habilitation> habilitations = new ArrayList<Habilitation>();
     
        /** Constructeur par defaut de la classe Intervenant 
        **/
    	public Intervenant(){
    		super();	
    	}
     
    	/** Constructeur  de la classe Intervenant 
            **/
    	public Intervenant(long idIntervenant,String nom,String prenom,String email,String fonction,String numTel,String numFax,Acces acces,Societe societe,String trigramme,String type,boolean actif){
    		super();	
    		this.idIntervenant = idIntervenant;
    		this.nom = nom;
    		this.prenom = prenom;
    		this.email = email;
    		this.fonction = fonction;
    		this.numTel = numTel;
    		this.numFax = numFax;
    		this.acces = acces;
    		this.societe = societe;
    		this.trigramme = trigramme;
    		this.type = type;
    		this.actif = actif;
     
    	}	
            ...tous les getters et setters des attributs de la classe
    }
    logHibernate.rar
    Fichiers attachés Fichiers attachés

  6. #6
    Expert confirmé
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 274
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 274
    Points : 4 141
    Points
    4 141
    Par défaut
    Il existe déjà ton intervenant en base ou pas ?
    En gros, tu veux faire un insert ou un update ?

  7. #7
    Futur Membre du Club
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    8
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2007
    Messages : 8
    Points : 5
    Points
    5
    Par défaut
    Non, en principe mon intervenant n'existe pas déjà en base. (Je remplis la base avec les données qu'il me faut au début de chaque test, et, si j'ai bien compris le principe de AbstractTransactionalDataSourceSpringContextTests, ces changements sont effacés à la fin du test).

  8. #8
    Expert confirmé
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 274
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 274
    Points : 4 141
    Points
    4 141
    Par défaut
    Dans ce cas là, utilise un simple save.

  9. #9
    Futur Membre du Club
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    8
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2007
    Messages : 8
    Points : 5
    Points
    5
    Par défaut
    Faut que j'essaye ça, effectivement, mais bon là, j'ai un peu tout cassé par ce que ma base de données était bancale. Je recode donc tout ça en espérant ne pas retomber sur une erreur de ce type. Mais ça me paraitrait quand même bizarre que ça marche avec save() et pas saveOrUpdate(). c quand même sensé faire à peu prés la même chose. Enfin bon merci quand même de vous être creusé la tête !

  10. #10
    Membre chevronné
    Homme Profil pro
    Directeur technique
    Inscrit en
    Janvier 2007
    Messages
    1 348
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Directeur technique

    Informations forums :
    Inscription : Janvier 2007
    Messages : 1 348
    Points : 1 787
    Points
    1 787
    Par défaut
    Je ne connais pas AbstractTransactionalDataSourceSpringContextTests mais effectivement ici le problème c'est que Hibernate se prend les pieds dans le tapis. Pour lui, intervenant1 existe déjà et donc il essaye de faire un update alors qu'en fait il n'existe pas en base -> plantage.

    Pourquoi ? Honnêtement là je ne sais pas, il faudrait creuser sur l'idée de AbstractTransactionalDataSourceSpringContextTests ...

  11. #11
    Membre régulier
    Inscrit en
    Octobre 2002
    Messages
    108
    Détails du profil
    Informations forums :
    Inscription : Octobre 2002
    Messages : 108
    Points : 98
    Points
    98
    Par défaut
    Essaye d'appeler session.flush() juste après getHibernateTemplate().saveOrUpdate() pour voir si ça marche ou pas.

  12. #12
    Membre chevronné
    Homme Profil pro
    Directeur technique
    Inscrit en
    Janvier 2007
    Messages
    1 348
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Directeur technique

    Informations forums :
    Inscription : Janvier 2007
    Messages : 1 348
    Points : 1 787
    Points
    1 787
    Par défaut
    Citation Envoyé par trungsi
    Essaye d'appeler session.flush() juste après getHibernateTemplate().saveOrUpdate() pour voir si ça marche ou pas.
    Si tu regardes bien la stack de l'exception, tu verras que ça ne va rien changer car le list justement appelle flush ...

  13. #13
    Membre régulier
    Inscrit en
    Octobre 2002
    Messages
    108
    Détails du profil
    Informations forums :
    Inscription : Octobre 2002
    Messages : 108
    Points : 98
    Points
    98
    Par défaut
    Est ce que la session utilisée dans HibernateTemplate (méthode getHibernateTemplate().saveOrUpdate()) est la même que celle utilisée dans getSession() (méthode getSession().createQuery()) ?

  14. #14
    Membre chevronné
    Homme Profil pro
    Directeur technique
    Inscrit en
    Janvier 2007
    Messages
    1 348
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Directeur technique

    Informations forums :
    Inscription : Janvier 2007
    Messages : 1 348
    Points : 1 787
    Points
    1 787
    Par défaut
    Même chose je suis presque certain que oui sinon le createQuery ne pourrait pas provoquer le flush ... mais ça vaut le coup de vérifier effectivement

Discussions similaires

  1. Problème avec la méthode request.form()
    Par sam.fet dans le forum ASP
    Réponses: 2
    Dernier message: 11/08/2006, 17h11
  2. [POO] Problème avec setInterval/méthodes d'écriture
    Par Lpu8er dans le forum Général JavaScript
    Réponses: 3
    Dernier message: 18/07/2006, 15h37
  3. problème avec la méthode getElementById() dans Firefox
    Par matrouba dans le forum Général JavaScript
    Réponses: 5
    Dernier message: 19/12/2005, 08h55
  4. Problème avec la méthode pack()
    Par tomca dans le forum Langage
    Réponses: 5
    Dernier message: 15/09/2005, 10h58
  5. Réponses: 11
    Dernier message: 29/04/2005, 19h45

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