Bonjour,
J'ai une application JEE avec des EJB et JPA (eclipseLink). J'ai deux entités client et adresse avec une relation onToMany de client vers adresse. J'ai une lazy exception lorsque je tente d'accés à la liste d'adresse d'un client (qui existe bien en base de donnée).
txtAdresse.setText(client.getAdresses().get(O).getAdresse());
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
| Exception in thread "AWT-EventQueue-0" Local Exception Stack:
Exception [EclipseLink-7242] (Eclipse Persistence Services - 2.0.1.v20100213-r6600): org.eclipse.persistence.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 org.eclipse.persistence.exceptions.ValidationException.instantiatingValueholderWithNullSession(ValidationException.java:979)
at org.eclipse.persistence.internal.indirection.UnitOfWorkValueHolder.instantiate(UnitOfWorkValueHolder.java:219)
at org.eclipse.persistence.internal.indirection.DatabaseValueHolder.getValue(DatabaseValueHolder.java:83)
at org.eclipse.persistence.indirection.IndirectList.buildDelegate(IndirectList.java:237)
at org.eclipse.persistence.indirection.IndirectList.getDelegate(IndirectList.java:397)
at org.eclipse.persistence.indirection.IndirectList.size(IndirectList.java:726)
at com.allgemark.clientLourd.swing.EditerClient.btnRechercherActionPerformed(EditerClient.java:727)
at com.allgemark.clientLourd.swing.EditerClient.access$4400(EditerClient.java:23)
at com.allgemark.clientLourd.swing.EditerClient$19.actionPerformed(EditerClient.java:450)
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:6267)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6032)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4460)
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) |
Voici un morceau de code de l'entité client:
1 2 3 4 5 6 7 8 9 10
|
..............
@OneToMany(cascade=CascadeType.ALL, fetch = FetchType.LAZY)
@JoinTable(joinColumns={@JoinColumn(name="client_fk")}, inverseJoinColumns={@JoinColumn(name="adresse_fk")})
private List<Adresse> adresses;
................
public List<Adresse> getAdresses() {
return adresses;
}
............ |
Si je remplace mes relations LAZY en EAGER je n'ai plus ce problème. Mais j'aimerai le faire fonctionner en LAZY mais je ne sais pas vraiment comment faire.
Je ne comprend de plus pas pourquoi le code suivant ne "reveille' pas l'entité en relation.
Merci d'avance
Partager