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 !