bonjour
voila dev avec NetBean un projet JEE qui a des Bean Entity pour faire la persistance dans une basse de donnée MySQL et la je me retrouve avec un probleme sur une relation @OneToMany je m'explique :
j'ai des Tiers qui on un Type (TypesTiers) quand je mette cette relation en place j'ai un erreur
Code:
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 package EJB.TableDesTiers; import EJB.TableAdresse.Adresse; import java.io.Serializable; import java.util.*; import javax.persistence.*; @Entity public class Tiers implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; public Long getId() { return id; } public void setId(Long id) { this.id = id; } @Column(nullable=false) private String NomTiers; public String getNomTiers() { return NomTiers; } public void setNomTiers(String NomTiers) { this.NomTiers = NomTiers; } (....) @OneToMany private List<Adresse> LesAdresses = new ArrayList<Adresse>(); public List<Adresse> getLesAdresses() { return LesAdresses; } public void setLesAdresses(List<Adresse> LesAdresses) { this.LesAdresses = LesAdresses; } @Override public String toString() { return NomTiers; } }
Code:
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 package EJB.TableTypesTiers; import EJB.TableDesTiers.Tiers; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import javax.persistence.*; @Entity public class TypesTiers implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.AUTO) private String NomDuType; public String getNomDuType() { return NomDuType; } public void setNomDuType(String NomDuType) { this.NomDuType = NomDuType; } @OneToMany public List<Tiers> tiers = new ArrayList<Tiers>(); public List<Tiers> getTiers() { return tiers; } public void setTiers(List<Tiers> tier) { this.tiers = tier; } @Override public String toString() { return NomDuType; } }
et lors de la persistance je me retrouve avec ceci :
A savoir que j'ai une relation @OneToMany entre mes tiers et leur adresse qui marche tres bienCitation:
Exception in thread "AWT-EventQueue-0" Local Exception Stack:
Exception [TOPLINK-7242] (Oracle TopLink Essentials - 2.1 (Build b60e-fcs (12/23/2008))): oracle.toplink.essentials.exceptions.ValidationException
Exception Description: An attempt was made to traverse a relationship using indirection that had a null Session. This often occurs when an entity with an uninstantiated LAZY relationship is serialized and that lazy relationship is traversed after serialization. To avoid this issue, instantiate the LAZY relationship prior to serialization.
at oracle.toplink.essentials.exceptions.ValidationException.instantiatingValueholderWithNullSession(ValidationException.java:887)
at oracle.toplink.essentials.internal.indirection.UnitOfWorkValueHolder.instantiate(UnitOfWorkValueHolder.java:233)
at oracle.toplink.essentials.internal.indirection.DatabaseValueHolder.getValue(DatabaseValueHolder.java:105)
at oracle.toplink.essentials.indirection.IndirectList.buildDelegate(IndirectList.java:208)
at oracle.toplink.essentials.indirection.IndirectList.getDelegate(IndirectList.java:332)
at oracle.toplink.essentials.indirection.IndirectList.add(IndirectList.java:155)
at client.JTest.jBAddTiersActionPerformed(JTest.java:461)
at client.JTest.access$500(JTest.java:31)
at client.JTest$6.actionPerformed(JTest.java:294)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6216)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
at java.awt.Component.processEvent(Component.java:5981)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4583)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4413)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4556)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4220)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4150)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4413)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)