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

Spring Java Discussion :

jpa et problème de transactions


Sujet :

Spring Java

  1. #1
    Membre actif

    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    127
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Janvier 2007
    Messages : 127
    Par défaut jpa et problème de transactions
    Bonjour,

    Nouvel utilisateur de Spring (venant des ejb 3), j'essaie en vain de mettre une annotation @Transactional sur mon service. Dès que je le fais, je ne peux plus instancier mon bean :-( J'ai passé des heures dessus, sans comprendre : cela marche pourtant bien sur la couche dao...

    Mon service s'appelle "taskoplanServiceImpl", ma dao "daoImpl".

    Dès que je rajoute l'annotation sur le service -->

    INFO: Binding service 'TaskoplanService' to RMI registry: RegistryImpl_Stub[UnicastRef [liveRef: [endpoint:[192.168.1.3:2484](remote),objID:[0:0:0, 0]]]]
    Exception in thread "main" java.lang.ClassCastException: $Proxy20 cannot be cast to be.lapinsoft.taskoplan.server.TaskoplanServiceImpl
    at be.lapinsoft.taskoplan.server.TaskoServ.main(TaskoServ.java:31)
    Voici le fichier xml de config de spring :

    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
    <?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:aop="http://www.springframework.org/schema/aop"
        xmlns:tx="http://www.springframework.org/schema/tx"
        xsi:schemaLocation="
            <a href="http://www.springframework.org/schema/beans" target="_blank">http://www.springframework.org/schema/beans</a> 
            <a href="http://www.springframework.org/schema/beans/spring-beans.xsd" target="_blank">http://www.springframework.org/schem...ring-beans.xsd</a> 
            <a href="http://www.springframework.org/schema/aop" target="_blank">http://www.springframework.org/schema/aop</a> 
            <a href="http://www.springframework.org/schema/aop/spring-aop-2.0.xsd" target="_blank">http://www.springframework.org/schem...ng-aop-2.0.xsd</a>
            <a href="http://www.springframework.org/schema/tx" target="_blank">http://www.springframework.org/schema/tx</a> 
            http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
        <bean id="taskoplanService" class="be.lapinsoft.taskoplan.server.TaskoplanServiceImpl">
            <property name="dao" ref="daoImpl" />
        </bean>
        <bean class="org.springframework.remoting.rmi.RmiServiceExporter">
            <!-- does not necessarily have to be the same name as the bean to be exported -->
            <property name="serviceName" value="TaskoplanService"/>
            <property name="service" ref="taskoplanService"/>
            <property name="serviceInterface" value="be.lapinsoft.taskoplan.remote.TaskoplanService" />
            <property name="registryPort" value="2484"/>
        </bean>
        <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor">
        </bean>
        <bean id="daoImpl" class="be.lapinsoft.taskoplan.server.DaoImpl">
            <!--property name="entityManagerFactory" ref="entityManagerFactory" /-->
        </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.TopLinkJpaVendorAdapter">
                    <property name="showSql" value="true" />
                    <property name="generateDdl" value="true" />
                    <property name="databasePlatform" value="oracle.toplink.essentials.platform.database.JavaDBPlatform"/>
                </bean>
            </property>
            <property name="loadTimeWeaver">
                <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
            </property>
        </bean>
        <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <property name="driverClassName" value="org.apache.derby.jdbc.ClientDriver" />
            <property name="url" value="jdbc:derby://localhost:1527/taskoplan" />
            <property name="username" value="taskoplan" />
            <property name="password" value="*****" />
        </bean>
        <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
            <property name="entityManagerFactory" ref="entityManagerFactory"/>
            <property name="dataSource" ref="dataSource"/>
        </bean>
        <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
        <tx:annotation-driven transaction-manager="transactionManager" />
    </beans>

  2. #2
    Membre actif

    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    127
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Janvier 2007
    Messages : 127
    Par défaut
    Personne n'a d'idées ?

    Je me demande si je ne devrais pas repasser en ejb3, où je n'ai jamais rencontré ce problème. Qu'en pensez-vous ?

  3. #3
    Rédacteur
    Avatar de Hikage
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    1 177
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : Belgique

    Informations forums :
    Inscription : Mai 2004
    Messages : 1 177
    Par défaut
    Peux tu montrer la ligne 31 de taskoServ.java?

    Apparement c'est à ce moment la que ca deconne, donc cela peut être utile de savoir ce qu'il s'y passe
    Hikage
    SCJP / SCWCD & SCWSJD Certified / Spring Framework Certified
    [Personal Web] [CV]

    F.A.Q Spring Framework - Participez !

  4. #4
    Membre actif

    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    127
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Janvier 2007
    Messages : 127
    Par défaut
    C'est quand j'essaie de caster le bean reçu :

    ApplicationContext springAppContext = new ClassPathXmlApplicationContext("META-INF/spring_server.xml");
    final TaskoplanServiceImpl service = (TaskoplanServiceImpl)springAppContext.getBean("taskoplanService");;

    Note que ça fonctionne bien si je ne mets pas ces annotations :-/

  5. #5
    Membre actif

    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    127
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Janvier 2007
    Messages : 127
    Par défaut
    Bon, je dois livrer bientôt, je repasse en ejb 3 :-/

  6. #6
    Rédacteur
    Avatar de Hikage
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    1 177
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : Belgique

    Informations forums :
    Inscription : Mai 2004
    Messages : 1 177
    Par défaut
    Tu peux tenter une chose ?

    Essaie de le caster non pas comme TaskServiceImpl mais comme TaskService pour voir
    Hikage
    SCJP / SCWCD & SCWSJD Certified / Spring Framework Certified
    [Personal Web] [CV]

    F.A.Q Spring Framework - Participez !

  7. #7
    Membre actif

    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    127
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Janvier 2007
    Messages : 127
    Par défaut
    Citation Envoyé par Hikage Voir le message
    Tu peux tenter une chose ?

    Essaie de le caster non pas comme TaskServiceImpl mais comme TaskService pour voir
    Oui, excellent, TOUT GRAND MERCI

    Tu as une explication (lien doc, ...) ? Je peux pas juste instancier TaskoplanServiceImpl ?

    Je croyais que ceci faisait que oui :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
        <bean id="taskoplanService" class="be.lapinsoft.taskoplan.server.TaskoplanServiceImpl">
            <property name="dao" ref="daoImpl" />
        </bean>
    Il est aussi exporté en rmi, c'est ça qui a une influence ?

    En tout cas, super, mon éternelle reconnaissance à toi :-)

  8. #8
    Rédacteur
    Avatar de Hikage
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    1 177
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : Belgique

    Informations forums :
    Inscription : Mai 2004
    Messages : 1 177
    Par défaut
    En fait, du moins c'est comme cela que je le comprends, le fait d'utiliser les annotations demande a Spring de gérer les transactions.

    Pour ce faire, Spring va créer un proxy, mais le proxy n'hérite pas de ta classe, mais par contre, Spring s'arrange pour que ce proxy implémente son interface.

    Donc tu peux effectivement caster sur l'interface sur service, mais plus sur son implémentation.


    De manière plus générale, c'est de toute manière mieux de ne pas s'attaché à une implémentation, mais d'utiliser l'interface, car cela te permet par la suite de change l'implémentation de manière tout à fait transparent pour le reste de l'application
    Hikage
    SCJP / SCWCD & SCWSJD Certified / Spring Framework Certified
    [Personal Web] [CV]

    F.A.Q Spring Framework - Participez !

Discussions similaires

  1. Réponses: 7
    Dernier message: 07/08/2008, 12h39
  2. Problème de Transactions
    Par blaspalles dans le forum Access
    Réponses: 4
    Dernier message: 18/09/2006, 18h05
  3. problème de transaction et load data
    Par jccanut dans le forum Installation
    Réponses: 6
    Dernier message: 14/09/2006, 12h38
  4. [SQL 2k] Problème de transaction choisie comme victime
    Par Actarion dans le forum MS SQL Server
    Réponses: 7
    Dernier message: 04/07/2006, 18h17
  5. Encore un petit problème de transaction
    Par devdev dans le forum MS SQL Server
    Réponses: 3
    Dernier message: 24/03/2005, 17h13

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