IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Java EE Discussion :

EJB3 et @ManyToOne : problème de marshalling


Sujet :

Java EE

  1. #1
    Candidat au Club
    Homme Profil pro
    Développeur Java
    Inscrit en
    Avril 2013
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Avril 2013
    Messages : 5
    Points : 2
    Points
    2
    Par défaut EJB3 et @ManyToOne : problème de marshalling
    Bonjour apres des heures et des heures de navigation sur tous les forum de la planete je viens poser ma question ici.

    Voilà j'aimerais savoir comment sérialiser un objet complexe à travers le reseau au travers des EJB. Je m'explique :

    en fait j'ai un objet avec des annotations @ManytoOne sur des attributs ArrayList
    J'utilisise la persistance sur hibernate et tout fonctionne. Cependant quand j'essaye de récupérer mon objet avec l'arraylist à l'interieur il me met :

    probleme d'ejb marshaling : en gros probleme de serialisation de la collection.

    Je pense que nombre d'entre vous on eu le soucis donc n'hésitez pas à me demander des précisions ou à me répondre.

    merci

  2. #2
    Membre émérite
    Homme Profil pro
    Développeur Java/Scala
    Inscrit en
    Octobre 2007
    Messages
    1 086
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java/Scala

    Informations forums :
    Inscription : Octobre 2007
    Messages : 1 086
    Points : 2 271
    Points
    2 271
    Par défaut
    Citation Envoyé par winsquall Voir le message
    Bonjour apres des heures et des heures de navigation sur tous les forum de la planete je viens poser ma question ici.

    Voilà j'aimerais savoir comment sérialiser un objet complexe à travers le reseau au travers des EJB. Je m'explique :

    en fait j'ai un objet avec des annotations @ManytoOne sur des attributs ArrayList
    J'utilisise la persistance sur hibernate et tout fonctionne. Cependant quand j'essaye de récupérer mon objet avec l'arraylist à l'interieur il me met :

    probleme d'ejb marshaling : en gros probleme de serialisation de la collection.

    Je pense que nombre d'entre vous on eu le soucis donc n'hésitez pas à me demander des précisions ou à me répondre.

    merci
    Avec Hibernate et autre les collections peuvent être chargées de manière lazy.

    C'est pas une idée super top de vouloir serialiser des entités qui ont potentiellement dans leur grappe d'objet des proxy qui s'occupent du lazyloading.

    En pratique il vaut mieux transformer tes objets en DTO qui eux sont garantis sans proxy et ensuite faire transiter ces DTO sur le réseau.

    Enfin après je sais pas, j'ai pas utilisé beaucoup les EJB3 et je crois qu'il y a certains trucs possibles et gérables avec du lazy loading a distance mais je sais pas trop...



    En tout cas t'es pas le seul a t'être deja posé la question ça c'est sur, et il y a divers moyens de déproxyfier ton objet avant de le faire transiter sur le réseau.

    Exemple: http://stackoverflow.com/questions/2...to-real-object

    Tu peux aussi essayer EntityManager.detach aussi... mais c'est pas sur que tes collections OneToMany soient déjà initialisées




    Sans l'exception c'est un peu compliqué a diagnostiquer
    React-Hebdo - Newsletter pour se tenir à jour sur l'écosystème React

  3. #3
    Candidat au Club
    Homme Profil pro
    Développeur Java
    Inscrit en
    Avril 2013
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Avril 2013
    Messages : 5
    Points : 2
    Points
    2
    Par défaut
    Citation Envoyé par HerQuLe Voir le message
    Avec Hibernate et autre les collections peuvent être chargées de manière lazy.

    C'est pas une idée super top de vouloir serialiser des entités qui ont potentiellement dans leur grappe d'objet des proxy qui s'occupent du lazyloading.

    En pratique il vaut mieux transformer tes objets en DTO qui eux sont garantis sans proxy et ensuite faire transiter ces DTO sur le réseau.

    Enfin après je sais pas, j'ai pas utilisé beaucoup les EJB3 et je crois qu'il y a certains trucs possibles et gérables avec du lazy loading a distance mais je sais pas trop...



    En tout cas t'es pas le seul a t'être deja posé la question ça c'est sur, et il y a divers moyens de déproxyfier ton objet avant de le faire transiter sur le réseau.

    Exemple: http://stackoverflow.com/questions/2...to-real-object

    Tu peux aussi essayer EntityManager.detach aussi... mais c'est pas sur que tes collections OneToMany soient déjà initialisées




    Sans l'exception c'est un peu compliqué a diagnostiquer
    Merci beaucoup pour ta réponse mais qui me donne d'autres questions.... Voici déjà l'erreur que génére le serveur :

    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
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    java.lang.RuntimeException: ClassNotFoundException marshaling EJB parameters 
        org.jboss.as.ejb3.remote.LocalEjbReceiver.clone(LocalEjbReceiver.java:229)
        org.jboss.as.ejb3.remote.LocalEjbReceiver.clone(LocalEjbReceiver.java:216)
        org.jboss.as.ejb3.remote.LocalEjbReceiver.processInvocation(LocalEjbReceiver.java:188)
        org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:179)
        org.jboss.ejb.client.TransactionInterceptor.handleInvocation(TransactionInterceptor.java:43)
        org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:181)
        org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:128)
        org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:181)
        org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:136)
        org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:121)
        org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104)
        $Proxy45.rechercherMembre(Unknown Source)
        ihm.membre.ControleurIhmBean.rechercherMembre(ControleurIhmBean.java:89)
        beanAction.RechercherMembre.execute(RechercherMembre.java:39)
        sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        java.lang.reflect.Method.invoke(Unknown Source)
        com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:453)
        com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:292)
        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:255)
        org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)
        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
        com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
        com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
        com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)
        org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
        com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
        com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)
        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
        com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:211)
        com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
        com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:211)
        com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
        com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190)
        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
        org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
        org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:90)
        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
        org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)
        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
        com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
        com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
        com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
        com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
        com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
        com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)
        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
        org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
        com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:192)
        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
        com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)
        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
        org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
        org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:510)
        org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
        org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
        org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
        org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
        org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
        org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
        org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153)
        org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
        org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368)
        org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
        org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671)
        org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930)
        java.lang.Thread.run(Unknown Source)
     
    java.lang.ClassNotFoundException: org.hibernate.collection.internal.PersistentBag from [Module "deployment.PicstoolsReboot.war:main" from Service Module Loader] 
        org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
        org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
        org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
        org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
        org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
        java.lang.Class.forName0(Native Method)
        java.lang.Class.forName(Unknown Source)
        org.jboss.marshalling.cloner.ClassLoaderClassCloner.clone(ClassLoaderClassCloner.java:46)
        org.jboss.marshalling.cloner.SerializingCloner.clone(SerializingCloner.java:158)
        org.jboss.marshalling.cloner.SerializingCloner.clone(SerializingCloner.java:135)
        org.jboss.marshalling.cloner.SerializingCloner.clone(SerializingCloner.java:187)
        org.jboss.marshalling.cloner.SerializingCloner.clone(SerializingCloner.java:135)
        org.jboss.marshalling.cloner.SerializingCloner$StepObjectInput.doReadObject(SerializingCloner.java:738)
        org.jboss.marshalling.AbstractObjectInput.readObject(AbstractObjectInput.java:37)
        org.jboss.marshalling.MarshallerObjectInputStream.readObjectOverride(MarshallerObjectInputStream.java:57)
        java.io.ObjectInputStream.readObject(Unknown Source)
        metier.membre.usager.Membre.readObject(Membre.java:179)
        sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        java.lang.reflect.Method.invoke(Unknown Source)
        org.jboss.marshalling.reflect.SerializableClass.callReadObject(SerializableClass.java:213)
        org.jboss.marshalling.cloner.SerializingCloner.initSerializableClone(SerializingCloner.java:302)
        org.jboss.marshalling.cloner.SerializingCloner.clone(SerializingCloner.java:254)
        org.jboss.marshalling.cloner.SerializingCloner.clone(SerializingCloner.java:135)
        org.jboss.marshalling.cloner.SerializingCloner$StepObjectInput.doReadObject(SerializingCloner.java:738)
        org.jboss.marshalling.AbstractObjectInput.readObject(AbstractObjectInput.java:37)
        org.jboss.marshalling.MarshallerObjectInputStream.readObjectOverride(MarshallerObjectInputStream.java:57)
        java.io.ObjectInputStream.readObject(Unknown Source)
        java.util.ArrayList.readObject(Unknown Source)
        sun.reflect.GeneratedMethodAccessor23.invoke(Unknown Source)
        sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        java.lang.reflect.Method.invoke(Unknown Source)
        org.jboss.marshalling.reflect.SerializableClass.callReadObject(SerializableClass.java:213)
        org.jboss.marshalling.cloner.SerializingCloner.initSerializableClone(SerializingCloner.java:302)
        org.jboss.marshalling.cloner.SerializingCloner.clone(SerializingCloner.java:254)
        org.jboss.marshalling.cloner.SerializingCloner.clone(SerializingCloner.java:135)
        org.jboss.as.ejb3.remote.LocalEjbReceiver.clone(LocalEjbReceiver.java:225)
        org.jboss.as.ejb3.remote.LocalEjbReceiver.clone(LocalEjbReceiver.java:216)
        org.jboss.as.ejb3.remote.LocalEjbReceiver.processInvocation(LocalEjbReceiver.java:188)
        org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:179)
        org.jboss.ejb.client.TransactionInterceptor.handleInvocation(TransactionInterceptor.java:43)
        org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:181)
        org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:128)
        org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:181)
        org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:136)
        org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:121)
        org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104)
        $Proxy45.rechercherMembre(Unknown Source)
        ihm.membre.ControleurIhmBean.rechercherMembre(ControleurIhmBean.java:89)
        beanAction.RechercherMembre.execute(RechercherMembre.java:39)
        sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        java.lang.reflect.Method.invoke(Unknown Source)
        com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:453)
        com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:292)
        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:255)
        org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)
        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
        com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
        com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
        com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)
        org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
        com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
        com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)
        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
        com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:211)
        com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
        com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:211)
        com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
        com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190)
        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
        org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
        org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:90)
        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
        org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)
        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
        com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
        com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
        com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
        com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
        com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
        com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)
        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
        org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
        com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:192)
        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
        com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)
        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
        org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
        org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:510)
        org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
        org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
        org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
        org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
        org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
        org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
        org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153)
        org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
        org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368)
        org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
        org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671)
        org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930)
        java.lang.Thread.run(Unknown Source)
    Voici mon EJB ENTITY MEMBRE qui pose probleme :

    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
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    package metier.membre.usager;
     
     
    import java.io.IOException;
    import java.io.ObjectInputStream;
    import java.io.ObjectOutputStream;
    import java.io.Serializable;
    import java.sql.Date;
    import java.util.ArrayList;
    import java.util.Collection;
     
    import metier.membre.intermediaire.MembreCategories;
     
     
    public class Membre implements Serializable {
     
    	/**
             * 
             */
    	private static final long serialVersionUID = 8958048505405006518L;
     
     
     
    	int id;
     
    	String nom;	
    	String prenom;
    	String pseudo;
     
    	String motDePasse;
     
    	Integer spuse;
     
    	Date dateDeNaissance;
     
    	boolean etatCompte;
     
    	String photo;
    	//Photos photos;
    	private transient Collection<MembreCategories> membreCategorie = new ArrayList<MembreCategories>();
    	private transient Collection<Coordonnees> coordonnees =	new ArrayList<Coordonnees>();
     
    	public Membre(int id, String nom, String prenom, String pseudo) {
    		super();
    		this.id = id;
    		this.nom = nom;
    		this.prenom = prenom;
    		this.pseudo = pseudo;
    	}
    	public Membre(String nom, String prenom, String pseudo, String motDePasse,
    			String email) {
    		super();
    		this.nom = nom;
    		this.prenom = prenom;
    		this.pseudo = pseudo;
    		this.motDePasse = motDePasse;
     
    	}
    	public Collection<MembreCategories> getMembreCategorie() {
    		return membreCategorie;
    	}
    	public void setMembreCategorie(Collection<MembreCategories> membreCategorie) {
    		this.membreCategorie = membreCategorie;
    	}
    	public Membre(int id) {
    		super();
    		this.id = id;
    	}
    	public Membre(String nom, String prenom, String pseudo, String email) {
    		super();
    		this.nom = nom;
    		this.prenom = prenom;
    		this.pseudo = pseudo;
     
    	}
    	public int getId() {
    		return id;
    	}
    	public void setId(int id) {
    		this.id = id;
    	}
    	public String getNom() {
    		return nom;
    	}
    	public void setNom(String nom) {
    		this.nom = nom;
    	}
    	public String getPrenom() {
    		return prenom;
    	}
    	public String getMotDePasse() {
    		return motDePasse;
    	}
    	public void setMotDePasse(String motDePasse) {
    		this.motDePasse = motDePasse;
    	}
    	public void setPrenom(String prenom) {
    		this.prenom = prenom;
    	}
    	public String getPseudo() {
    		return pseudo;
    	}
    	public void setPseudo(String pseudo) {
    		this.pseudo = pseudo;
    	}
    	public int getSpuse() {
    		return spuse;
    	}
    	public void setSpuse(int spuse) {
    		this.spuse = spuse;
    	}
    	public Date getDateDeNaissance() {
    		return dateDeNaissance;
    	}
    	public void setDateDeNaissance(Date dateDeNaissance) {
    		this.dateDeNaissance = dateDeNaissance;
    	}
    	public boolean isEtatCompte() {
    		return etatCompte;
    	}
    	public void setEtatCompte(boolean etatCompte) {
    		this.etatCompte = etatCompte;
    	}
    	public String getPhoto() {
    		return photo;
    	}
    	public void setPhoto(String photo) {
    		this.photo = photo;
    	}
    	public void add(MembreCategories membreCategorie){
    		this.membreCategorie.add(membreCategorie);
    	}
     
    	public void add(Coordonnees coordonnees){
    		this.coordonnees.add(coordonnees);
    	}
     
     
     
    	public Membre() {
    		super();
    		// TODO Auto-generated constructor stub
    	}
     
     
    	@Override
    	public String toString() {
    		return "Membre [id=" + id + ", nom=" + nom + ", prenom=" + prenom
    				+ ", pseudo=" + pseudo + ", motDePasse=" + motDePasse
    				+ ", spuse=" + spuse + ", dateDeNaissance=" + dateDeNaissance
    				+ ", etatCompte=" + etatCompte + ", photo=" + photo + "]";
    	}
    	public Collection<Coordonnees> getCoordonnees() {
    		return coordonnees;
    	}
    	public void setCoordonnees(Coordonnees coordonnees) {
    		this.coordonnees.add(coordonnees);
    	}
    Et voici la requete que j'effectue via mon entitymanager qui est en hql ( select m from Membre m):
    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("unchecked")
    	@Override
    	public ArrayList<Membre> listerTousLesMembres(Membre membre){
     
    		// Pr�paration des variables pour la recherche
    		String where = "where";
    		String and		= "and";
    		String rechercheNom = " ";
    		String recherchePrenom = " ";
    		String recherchePseudo = " ";
    		String rechercheEmail = " ";
     
    		// V�rification des attributs pour adapter la recherche
     
    		if (membre.getNom() != null)
    			rechercheNom = "where m.nom like '%" + membre.getNom() +"%'";
     
    		if (membre.getPrenom() != null){
     
    			if (membre.getNom() == null){
     
    				recherchePrenom = where + " " +  "m.prenom like '%" + membre.getPrenom() + "%'";
    			}
    			else if (membre.getNom() != null){
     
    				recherchePrenom = and +" " + "m.prenom like '%" + membre.getPrenom() + "%'";
    			}
    		}
     
    		if (membre.getPseudo() != null){
     
    			if (membre.getNom() == null && membre.getPrenom() == null){
     
    				recherchePseudo = where + " " + " m.pseudo like '%" + membre.getPseudo() + "%'";
    			}
    			else if (membre.getNom() != null & membre.getPrenom() != null){
     
    				recherchePseudo = and + " " + " m.pseudo like '%" + membre.getPseudo() + "%'";
    			}
    		}	
     
     
     
     
    		return (ArrayList<Membre>) em.createQuery("SELECT m FROM Membre m "	+ rechercheNom + recherchePrenom + recherchePseudo +rechercheEmail ).getResultList();
     
     
    	}
    Si je passe les collections avec une annotation @Transient tout va bien hibernate n'y touche plus ...

    Note : je suis sous jdk7, jboss7

  4. #4
    Membre émérite
    Homme Profil pro
    Développeur Java/Scala
    Inscrit en
    Octobre 2007
    Messages
    1 086
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java/Scala

    Informations forums :
    Inscription : Octobre 2007
    Messages : 1 086
    Points : 2 271
    Points
    2 271
    Par défaut
    En fait il se trouve que c'est bien un problème de serialisation lié au LazyLoading etc d'Hibernate.


    Il se trouve que quand tu récupères le résultat de ta requête, pour tes collections de membres et de catégories, Hibernate ne créé pas réellement une collection Java derrière le capot, mais une PersistentCollection (ici PersistentBag).

    PersistentBag est un type de collection particulier car en réalité elle ne contient pas encore vraiment les éléments. Par contre, lorsque tu essaies d'y accéder, cet objet effectuera une vraie requête a la base pour charger les categories (ou coordonnées).


    Le problème est que c'est cette classe qui est serialisée, une classe spécifique à Hibernate!
    Si ça ne marche pas, c'est parce que coté client, tu n'as pas dans ton classpath de PersistentBag (car Hibernate n'est pas dans ton classpath coté client).
    Même si tu avais un PersistentBag de l'autre coté, il est probable que ça ne marche pas très bien car ta partie cliente essaierai de reproduire le lazyloading d'hibernate coté serveur mais ne pourrait pas.

    Il semble que ca soit tout de même possible d'utiliser le lazy loading en mode remote, mais je ne recommande pas vraiment:
    http://www.theserverside.com/news/13...g-in-Hibernate

    Pour moi Hibernate n'a probablement pas besoin d'être dans ton classpath coté client.

    Encore une fois, mieux faut enlever les proxy de ton objet avant de les serializer:
    http://stackoverflow.com/a/2216603

    Sinon tu transformes tes objets en DTO à la mano -> peut être utile si tu n'as pas besoin de renvoyer toutes les données en fonction de l'usage de tes services distants.


    Pour t'assurer de la bonne communication entre le client et le serveur il vaut s'assurer que les classes serialisées sont à la fois connues du client et du serveur.

    Donc il faut créer des objets spécifiques (DTO) et les mettre dans le classpath des deux cotés, ou alors tu utilises des classes du jdk (genre ArrayList).

    La methode de deproxification des entités hibernate citée au dessus doit probablement remplacer le PersistentBag par une ArrayList -> ArrayList est connu coté client et serveur, donc ca devrait résoudre ton problème.
    React-Hebdo - Newsletter pour se tenir à jour sur l'écosystème React

  5. #5
    Candidat au Club
    Homme Profil pro
    Développeur Java
    Inscrit en
    Avril 2013
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Avril 2013
    Messages : 5
    Points : 2
    Points
    2
    Par défaut
    Merci beaucoup donc je vois mieux ce que tu entends... enfin je pense : laisses moi résumer :

    - Soit j’enlève de mon objet les collections vide qui sont présentes
    - Soit je créée un objet hybride (DTO) qui récupère les infos dont j'ai besoin sous forme d'attribut simple que je puisse passer à travers le réseau.
    - Soit je passe en EAGER au mépris de performance

    Je vais essayé tout ça mais la discussion m’intéresse vraiment. Je me demande vraiment pourquoi les accès distant posent tant de problèmes et pourquoi les solutions sont si dures à trouver....

  6. #6
    Membre émérite
    Homme Profil pro
    Développeur Java/Scala
    Inscrit en
    Octobre 2007
    Messages
    1 086
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java/Scala

    Informations forums :
    Inscription : Octobre 2007
    Messages : 1 086
    Points : 2 271
    Points
    2 271
    Par défaut
    Citation Envoyé par winsquall Voir le message
    Merci beaucoup donc je vois mieux ce que tu entends... enfin je pense : laisses moi résumer :

    - Soit j’enlève de mon objet les collections vide qui sont présentes
    - Soit je créée un objet hybride (DTO) qui récupère les infos dont j'ai besoin sous forme d'attribut simple que je puisse passer à travers le réseau.
    - Soit je passe en EAGER au mépris de performance

    Je vais essayé tout ça mais la discussion m’intéresse vraiment. Je me demande vraiment pourquoi les accès distant posent tant de problèmes et pourquoi les solutions sont si dures à trouver....
    Oui c'est a peu près ca

    Je ne suis pas sur que passer en mode Eager te fournisse des collections non persistantes (= proxifiées) car ces collections persistantes ne semblent pas serveir qu'au lazy loading mais aussi au suivi des modifications faites sur les collections.

    En plus normalement je ne crois pas que tu puisses charger 2 collections en mode Eager.
    Voir: http://256.com/gray/docs/misc/hibern...lections.shtml


    L'idée n'est pas d'enlever les objets les collections vides, mais de remplacer des collections internes a Hibernate pas des implémentations connues à la fois par le client et le serveur.
    Donc en gros il faut remplacer PersistentBag par ArrayList.


    Limite tu le fais à la main avec de serialiser ça marche aussi

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    obj.setCategories( new ArrayList<Category>(obj.getCategories) );
    Bon c'est plus propre et générique d'utiliser la methode de deproxyfication Hibernate donnée sur StackOverflow quand même, mais c'est l'idée au final
    React-Hebdo - Newsletter pour se tenir à jour sur l'écosystème React

  7. #7
    Membre émérite
    Homme Profil pro
    Développeur Java/Scala
    Inscrit en
    Octobre 2007
    Messages
    1 086
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java/Scala

    Informations forums :
    Inscription : Octobre 2007
    Messages : 1 086
    Points : 2 271
    Points
    2 271
    Par défaut
    Bon au final il semble que la deproxyfication permet d'enlever le lazy loading, mais ne change pas le PersistantBag en ArrayList.


    Voir ici:
    http://stackoverflow.com/questions/8...m-entity-pojos


    En fait il te faudrait donc bien passer par des DTO ce qui permet de bien découpler ton client
    de ton serveur par la même occasion.

    Ils doivent donc partager un projet/jar commun qui contiendra tous les DTO qui transitent sur le réseau.
    React-Hebdo - Newsletter pour se tenir à jour sur l'écosystème React

  8. #8
    Candidat au Club
    Homme Profil pro
    Développeur Java
    Inscrit en
    Avril 2013
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Avril 2013
    Messages : 5
    Points : 2
    Points
    2
    Par défaut
    Si je suis ton idée du DTO, j'ai écris cette modification dans ma methode de récupération DAO. En fait je crée une arraylist et un membre détaché du contexte de persistence et après j'itere l'arraylist récupéré d'Hibernate.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    ArrayList<Membre> list = new ArrayList<Membre>();
    		Iterator<Membre> iter = em.createQuery("SELECT m FROM Membre m "	+ rechercheNom + recherchePrenom + recherchePseudo +rechercheEmail ).getResultList().iterator();
    		while (iter.hasNext()){
    			Membre membre1 = iter.next();
    			Membre membre2 = new Membre();
    			membre2.setId(membre.getId());
    			membre2.setNom(membre1.getNom());
    			list.add(membre2);
     
    		}
    Tu pensais à ceci?

  9. #9
    Membre émérite
    Homme Profil pro
    Développeur Java/Scala
    Inscrit en
    Octobre 2007
    Messages
    1 086
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java/Scala

    Informations forums :
    Inscription : Octobre 2007
    Messages : 1 086
    Points : 2 271
    Points
    2 271
    Par défaut
    Bien perso j'aurais:

    - Créé la query avec l'API Criteria (Hibernate, sinon JPA2) qui est vraiment super utile pour les query dynamiques

    - Créé un DTO MembreIdAndNameDTO

    - Je suis pas spécialement fan de la verbosité d'utiliser Iterator car on itère très bien sur une liste depuis Java5



    Mais sinon c'est l'idée oui.
    Tu gagnes même en performance car tu es sur de ne pas charger les collections sauf si tu en as vraiment besoin.

    Le seul risque dans ton code c'est de te retrouver avec parfois des objets Membre avec tous leurs attributs, et parfois que 2 attributs. Il vaut mieux être explicite et créer un DTO à part plutôt que de réutiliser ton entité comme un DTO.

    L'avantage c'est aussi que ton client n'est même plus obligé d'hériter des sources de ton serveur, il n'a plus besoin de partager que les DTO qui transitent sur le réseau. Alors que sinon il doit avoir connaissance des entités.

    En gros ton client a connaissance de classes qui sont utilisées pour le stockage des entités Hibernate.
    Si demain tu veux réorganiser ton stockage des objets, changer tes relations, tu devras alors réorganiser ton code client.
    Il est préférable de réduire au maximum le couplage entre les différentes couches de ton application.
    React-Hebdo - Newsletter pour se tenir à jour sur l'écosystème React

  10. #10
    Candidat au Club
    Homme Profil pro
    Développeur Java
    Inscrit en
    Avril 2013
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Avril 2013
    Messages : 5
    Points : 2
    Points
    2
    Par défaut
    Merci beaucoup, problème résolu

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [JAXB] [Java 1.5] Problème de marshalling
    Par Soulama dans le forum Format d'échange (XML, JSON...)
    Réponses: 2
    Dernier message: 18/04/2013, 10h45
  2. Problème avec Marshal.PtrToStructure
    Par maladebe dans le forum C++/CLI
    Réponses: 2
    Dernier message: 20/02/2009, 14h14
  3. [VS2005] Problème de marshalling et de tableau
    Par pdgnr dans le forum Windows Forms
    Réponses: 3
    Dernier message: 12/09/2008, 14h11
  4. Problème de Marshaling de tableaux
    Par stephane.julien dans le forum C#
    Réponses: 1
    Dernier message: 13/05/2008, 11h23
  5. Problème de marshaling char[][] -> System.String
    Par vdew1405 dans le forum C++/CLI
    Réponses: 2
    Dernier message: 20/08/2007, 10h12

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo