Bonjour,
J'utilise Java5, JPA/Hibernate et spring, dans une petit application prototype.
Dans cette application j'ai des liens entre 3 entités : P06deodsp ,P05eodsp etP04todsp
j'ai 3 entités, la 1er est :
la deuxième est :
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 @SuppressWarnings("unused") @Entity @Table(name="P06DEODSP") public class P06deodsp extends BaseObject implements Serializable { private static final long serialVersionUID = 3830326162173359411L; @Id @Column(name = "P06IDPKDEO", nullable = false) @GeneratedValue(strategy = GenerationType.AUTO) private int p06idpkdeo; // --- Relation principale P06 (many) --> P07 (One) // --- implèmentée par une clè étrangère () dans P06 @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="P06IDCHG", nullable = true) private P07cochgp p07cochgp; // --- Relation principale P06 (many) --> P03 (One) // --- implèmentée par une clè étrangère (P06IDPKZDB) dans P06 @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="P06IDPKZDB", nullable = false) private P03zdbhip p03zdbhip; // --- Relation principale P06 (many) --> P05 (One) // --- implèmentée par une clè étrangère (P06IDPKEOD) dans P06 @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="P06IDPKEOD", nullable = false) private P05eodsp p05eodsp; @Column(name = "P06RANG", nullable = false) private short p06rang; @Column(name = "P06DESIGN", length = 30) private String p06design; @Column(name = "P06POS", nullable = false) private short p06pos; @Column(name = "P06TAILLE", nullable = false) private short p06taille; @Column(name = "P06OBLIG", length = 1 ,nullable = false) private char p06oblig; @Column(name = "P06REGLE", length = 20 ,nullable = false) private String p06regle; @Column(name = "P06ATRAIT", length = 1 ,nullable = false) private char p06atrait;
et la 3éme est :
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 @SuppressWarnings("unused") @Entity @Table(name="P05EODSP") public class P05eodsp extends BaseObject implements Serializable { private static final long serialVersionUID = 3831026162173359411L; @Id @Column(name = "P05IDPKEOD", nullable = false) @GeneratedValue(strategy = GenerationType.AUTO) private int p05idpkeod; // --- Relation principale P05 (many) --> P04 (One) // --- implèmentée par une clè étrangère (P05IDPKODS) dans P06 @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="P05IDPKODS", nullable = false) private P04todsp p04todsp; @Column(name = "P05ENTITE", length = 10 ,nullable = false) private String p05entite; @Column(name = "P05DESIGN", length = 40) private String p05design; @Column(name = "P05ATRAIT", length = 1 ,nullable = false) private char p05atrait; // --- Relation inverse P05 (One) --> P06 (Many) @OneToMany(mappedBy= "p05eodsp" , cascade = {CascadeType.ALL}) private Set<P06deodsp> p06deodsps = new HashSet<P06deodsp>();
Mon fichier Spring est le suivant :
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 @SuppressWarnings("unused") @Entity @Table(name="P04TODSP") public class P04todsp extends BaseObject implements Serializable { private static final long serialVersionUID = 3896626162173359411L; @Id @Column(name = "P04IDPKODS", nullable = false) @GeneratedValue(strategy = GenerationType.AUTO) private int p04idpkods; // --- Relation principale P04 (many) --> P01 (One) // --- implèmentée par une clè étrangère (P04IDPKIP) dans P06 @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="P04IDPKIP", nullable = false) private P01ipmacp p01ipmacp; @Column(name = "P04TABLE", length = 10 ,nullable = false) private String p04table; @Column(name = "P04DESIGNT", length = 40) private String p04designt; @Column(name = "P04ZONE", length = 10 ,nullable = false) private String p04zone; @Column(name = "P04DESIGNZ", length = 40) private String p04designz; @Column(name = "P04TYPE", length = 10 ,nullable = false) private String p04type; @Column(name = "P04TAILLE", nullable = false) private BigDecimal p04taille; @Column(name = "P04ATRAIT", length = 1 ,nullable = false) private char p04atrait; // --- Relation inverse P04 (One) --> P05 (Many) @OneToMany(mappedBy= "p04todsp" , cascade = {CascadeType.ALL}) private Set<P05eodsp> p05eodsps = new HashSet<P05eodsp>();
lorsque j'essaie de recupérer l'entité P05eodsp à partir de l'entité P06deodsp j'ai l'erreur 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
51
52
53
54
55
56
57
58
59 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"> <!-- couches applicatives --> <bean id="dao" class="odas.toolbox.persistance.dao.Dao" /> <bean id="universalDao" class="odas.toolbox.persistance.dao.UniversalDao" /> <bean id="service" class="odas.toolbox.persistance.service.Service"> <property name="dao" ref="dao" /> </bean> <bean id="universalManager" class="odas.toolbox.service.impl.UniversalManagerImpl"> <property name="universalDao" ref="universalDao" /> </bean> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> <property name="showSql" value="true" /> <property name="databasePlatform" value="org.hibernate.dialect.DB2400Dialect" /> <property name="generateDdl" value="false" /> </bean> </property> <property name="loadTimeWeaver"> <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" /> </property> </bean> <!-- la source de donnéees DBCP --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="com.ibm.as400.access.AS400JDBCDriver" /> <property name="url" value="jdbc:as400://tersudm/decision" /> <property name="username" value="CFT" /> <property name="password" value="CFT" /> </bean> <!-- le gestionnaire de transactions --> <tx:annotation-driven transaction-manager="txManager" /> <bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory" /> </bean> <!-- traduction des exceptions --> <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" /> <!-- persistence --> <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /> </beans>
Merci d'avance pour votre aide
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 Hibernate: select p06deodsp0_.P06IDPKDEO as P1_5_, p06deodsp0_.P06IDCHG as P10_5_, p06deodsp0_.P06IDPKZDB as P9_5_, p06deodsp0_.P06IDPKEOD as P11_5_, p06deodsp0_.P06RANG as P2_5_, p06deodsp0_.P06DESIGN as P3_5_, p06deodsp0_.P06POS as P4_5_, p06deodsp0_.P06TAILLE as P5_5_, p06deodsp0_.P06OBLIG as P6_5_, p06deodsp0_.P06REGLE as P7_5_, p06deodsp0_.P06ATRAIT as P8_5_ from P06DEODSP p06deodsp0_ Hibernate: select p06deodsp0_.P06IDPKDEO as P1_5_0_, p06deodsp0_.P06IDCHG as P10_5_0_, p06deodsp0_.P06IDPKZDB as P9_5_0_, p06deodsp0_.P06IDPKEOD as P11_5_0_, p06deodsp0_.P06RANG as P2_5_0_, p06deodsp0_.P06DESIGN as P3_5_0_, p06deodsp0_.P06POS as P4_5_0_, p06deodsp0_.P06TAILLE as P5_5_0_, p06deodsp0_.P06OBLIG as P6_5_0_, p06deodsp0_.P06REGLE as P7_5_0_, p06deodsp0_.P06ATRAIT as P8_5_0_ from P06DEODSP p06deodsp0_ where p06deodsp0_.P06IDPKDEO=? 17:14:51,133 ERROR LazyInitializationException:19 - could not initialize proxy - the owning Session was closed org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:60) at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111) at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:172) at odas.toolbox.persistance.jpa.hibernate.model.P05eodsp$$EnhancerByCGLIB$$b9ad7f0d.getP04todsp(<generated>) at odas.toolbox.persistance.GestionnaireParametrageEngine.performBatch(GestionnaireParametrageEngine.java:428) at odas.toolbox.persistance.GestionnaireParametrageEngine.performBatch(GestionnaireParametrageEngine.java:396) at odas.toolbox.rmi.test.TestPersistance.main(TestPersistance.java:22)
Partager