Bonjour,

Je commence à me familiariser avec Hibernate et j'ai un petit soucis en récupérant une liste. Alors comme un exemple vaux mieux qu'un long discours ...

J'ai une relation 1/n entre 2 tables "Flux" et "Theme"
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
 
<hibernate-mapping>
 
    <class name="Flux" table="FLUX">
        <id name="codeFlux" column="CODE_FLUX">
            <generator class="assigned"/>
        </id>
        <property name="libelleFlux" type="java.lang.String" column="LIBELLE_FLUX"/>
 
        <many-to-one 	name="theme"
        				class="Theme" 
        				column="ID_THEME" 
        				not-null="true"/>
 
    </class>
 
</hibernate-mapping>
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
 
<hibernate-mapping>
 
    <class name="Theme" table="THEME">
        <id name="idTheme" column="ID_THEME">
            <generator class="increment"/>
        </id>
        <property name="libelleTheme" type="java.lang.String" column="LIBELLE_THEME"/>
 
 
        <list name="listeFlux" table="FLUX">
		     <key column="ID_THEME"/>
		     <index column="CODE_FLUX"/>
		     <one-to-many class="Flux"/>
	 	</list>	
 
    </class>
 
</hibernate-mapping>
Ma classe Theme
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
 
public class Theme {
 
    private Integer idTheme;
    private String libelleTheme;
    private List listeFlux = new ArrayList();
 
    ...
}
Ma classe Flux
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
 
public class Flux {
 
    private String codeFlux;
    private String libelleFlux;
    private Theme theme;
 
    ...
}
Et lorsque je veux récupérer la liste des flux associés à un thème, j'ai une exception

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
 
Theme theme = (Theme)session.get(Theme.class, new Integer(2));
 
List<Flux> listeFlux = theme.getListeFlux();
 
for(int i=0; i<listeFlux.size(); i++) {
    System.out.println(listeFlux.get(i).getCodeFlux());
}
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
 
Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not initialize a collection: [Theme.listeFlux#2]
	at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
	at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
	at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
	at org.hibernate.loader.Loader.loadCollection(Loader.java:2001)
	at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:36)
	at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:565)
	at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:63)
	at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1716)
	at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:344)
	at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
	at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:109)
	at org.hibernate.collection.PersistentList.size(PersistentList.java:91)
	at TestHibernate.main(TestHibernate.java:23)
Caused by: java.sql.SQLException: Echec de conversion dans la représentation interne
	at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
	at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
	at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:269)
	at oracle.jdbc.driver.OracleStatement.getIntValue(OracleStatement.java:4479)
	at oracle.jdbc.driver.OracleResultSetImpl.getInt(OracleResultSetImpl.java:536)
	at oracle.jdbc.driver.OracleResultSet.getInt(OracleResultSet.java:1528)
	at com.mchange.v2.c3p0.impl.NewProxyResultSet.getInt(NewProxyResultSet.java:2573)
	at org.hibernate.type.IntegerType.get(IntegerType.java:28)
	at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:163)
	at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:154)
	at org.hibernate.persister.collection.AbstractCollectionPersister.readIndex(AbstractCollectionPersister.java:708)
	at org.hibernate.collection.PersistentList.readFrom(PersistentList.java:379)
	at org.hibernate.loader.Loader.readCollectionElement(Loader.java:1008)
	at org.hibernate.loader.Loader.readCollectionElements(Loader.java:646)
	at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:591)
	at org.hibernate.loader.Loader.doQuery(Loader.java:701)
	at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
	at org.hibernate.loader.Loader.loadCollection(Loader.java:1994)
	... 9 more
Je ne trouve pas de sujet correspondant à mon problème.
J'ajouterais que j'utilise Hibernate 3 avec un Oracle 9.2.0.3 + ojdbc14.jar

Merci à vous pour votre aide