Bonjour,

J'utilise hibernate afin de persister mes données. Pour les tests unitaires j'utilise HSQLDB.

Deux classes sont persistées :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
 
@Entity
@Table(name = "INDICATEUR", schema = "ECLERGENERIQUE")
public class Indicateur implements Serializable {
 
	@Id
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_INDICATEUR")
	@SequenceGenerator(name = "SEQ_INDICATEUR", sequenceName = "INDICATEUR_SEQUENCE", allocationSize = 1)
	@Column(name = "INDICATEUR_ID", nullable = false, insertable = false, updatable = false)
	private Long id;
......
}
et

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
 
@Entity
@Table(name = "INFO_INDICATEUR", schema = "ECLERGENERIQUE")
public class InfoIndicateur implements Serializable
{
	@Id
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_INFO_INDICATEUR")
	@SequenceGenerator(name = "SEQ_INFO_INDICATEUR", sequenceName = "INFO_INDICATEUR_SEQUENCE", allocationSize = 1)
	@Column(name = "INFO_INDICATEUR_ID", nullable = false, insertable = false, updatable = false)
	private Long id = -1L;
 
	@ManyToOne
	@JoinColumn(name = "indicateur_id")
	Indicateur indicateur;
....}
il y a une relation many-to-one entre InfoIndicateur et Indicateur.

dans la méthode setUp() de mon test unitaire (JUnit) je tente d'enregistrer à la suite plusieurs instance d'Indicateur et d'InfoIndicateur :
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
 
	public void setUp() throws Exception
	{
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		Long id = 1L;
		Long idInfo = 1L;
 
		//GRIFFE A
		Indicateur ind = new Indicateur();
		ind.setDescription("indique l état du flux GRIFFE");
		ind.setFamille("GRIFFE");
		ind.setLigne("A");
		ind.setNom(IndicateurManager.ETAT_FLUX_GRIFFE);
		ind.setId(id++);
		session.save(ind);
 
		InfoIndicateur info = new InfoIndicateur();
		info.setId(idInfo++);
		info.setIndicateur(ind);
		info.setNom("DATE_MAJ");
		info.setInfo_date(GregorianCalendar.getInstance().getTime());
		session.save(info);
 
		info = new InfoIndicateur();
		info.setId(idInfo++);
		info.setIndicateur(ind);
		info.setNom("VIE");
		info.setInfo_date(GregorianCalendar.getInstance().getTime());
		session.save(info);
 
		info = new InfoIndicateur();
		info.setId(idInfo++);
		info.setIndicateur(ind);
		info.setNom("QUALITE_FLUX");
		info.setInfo_float(new Float(0.75));
		session.save(info);
 
 
		//GRIFFE B
		ind = new Indicateur();
		ind.setId(id++);
		ind.setDescription("indique l état du flux GRIFFE");
		ind.setFamille("GRIFFE");
		ind.setLigne("B");
		ind.setNom(IndicateurManager.ETAT_FLUX_GRIFFE);
		session.save(ind);
 
		info = new InfoIndicateur();
		info.setId(idInfo++);
		info.setIndicateur(ind);
		info.setNom("DATE_MAJ");
		info.setInfo_date(GregorianCalendar.getInstance().getTime());
		session.save(info);
 
		info = new InfoIndicateur();
		info.setId(idInfo++);
		info.setIndicateur(ind);
		info.setNom("VIE");
		info.setInfo_date(GregorianCalendar.getInstance().getTime());
		session.save(info);
 
		info = new InfoIndicateur();
		info.setId(idInfo++);
		info.setIndicateur(ind);
		info.setNom("QUALITE_FLUX");
		info.setInfo_float(new Float(0.75));
		session.save(info);
 
		session.getTransaction().commit();
}
lors du commit à la fin du code j'obtiens la magnifique exception 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
 
Hibernate: 
    /* insert com.sncf.gl.app.ecler.admin.dto.Indicateur
        */ insert 
        into
            ECLERGENERIQUE.INDICATEUR
            (DESCRIPTION, FAMILLE, LIGNE, NOM, INDICATEUR_ID) 
        values
            (?, ?, ?, ?, ?)
19641 [main] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 0, SQLState: null
19641 [main] ERROR org.hibernate.util.JDBCExceptionReporter - failed batch
19641 [main] ERROR org.hibernate.event.def.AbstractFlushingEventListener - Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
	at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126)
	at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)
	at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
	at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
	at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
	at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
	at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1028)
	at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:366)
	at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
	at com.sncf.gl.app.ecler.admin.da.JunitTest.GriffeTest.setUp(GriffeTest.java:99)
	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:585)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
à priori c'est sur l'insertion de la seconde instance d'Indicateur???

J'ai essayé des flush après chaque save, des commit après chaque nouvel objet. Rien n'y fait..

J'ai l'impression de tourner en rond..

Si quelqu'un a déjà vu ce pb (et l'a résolu...) je suis preneur.

merci d'avance.