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 Web Java Discussion :

probleme avec proprietes mappingResources


Sujet :

Spring Web Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Candidat au Club
    Inscrit en
    Septembre 2009
    Messages
    3
    Détails du profil
    Informations forums :
    Inscription : Septembre 2009
    Messages : 3
    Par défaut probleme avec proprietes mappingResources
    Je rencontre un problème dans un projet. Je fais l'integration d'hibernate dans un projet spring j'ai un problème très simple j'ai totalement enlevé le fichier de configuration de hibernate et je l'ai remplacé par un bean sessionFactory et c'est la qu'est réside mon problème,je dois spécifier les fichiers mapping. C'est pour cela que j'utilise la propriètes mappingResources mais je reçois toujours une erreur 503.
    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
     
    <?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:p="http://www.springframework.org/schema/p"
           xmlns:aop="http://www.springframework.org/schema/aop"
           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.5.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
     
        <!--bean id="propertyConfigurer"
              class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
              p:location="/WEB-INF/jdbc.properties" />
     
        <bean id="dataSource"
              class="org.springframework.jdbc.datasource.DriverManagerDataSource"
              p:driverClassName="${jdbc.driverClassName}"
              p:url="${jdbc.url}"
              p:username="${jdbc.username}"
              p:password="${jdbc.password}" /-->
     
        <!-- ADD PERSISTENCE SUPPORT HERE (jpa, hibernate, etc) -->
        <bean id="implProduit" class="akatsuki.domain.service.implProduit">
            <property name="produitDao" ref="produitDaoHibernate"/>
        </bean>
     
        <bean id="produitDaoHibernate" class="akatsuki.domain.repositryimpl.ProduitDaoHibernate" >
            <property name="hibernateTemplate" ref="hibernateTemplate"/>
        </bean>
     
        <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
            <property name="sessionFactory">
                <ref bean="mySessionFactory"/>
            </property>
        </bean>
     
        <bean id="mySessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
            <property name="hibernateProperties">
                <props>
                    <prop key="hibernate.connection.driver_class">com.mysql.jdbc.Driver</prop>
                    <prop key="hibernate.connection.url">jdbc:mysql://localhost:3306/achat</prop>
                    <prop key="hibernate.connection.username">root</prop>
                    <prop key="hibernate.connection.password">bankai</prop>
                    <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                </props>
            </property>
            <property name="mappingResources">
                <list>
                    <value>Produit.hbm.xml</value>
                </list>
            </property>
     
        </bean>
     
     
        <bean id="TransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
            <property name="sessionFactory"><ref local="mySessionFactory"/></property>
        </bean>
     
    </beans>
    quand je regarde la pile d'erreur sa me dit que le fichier Produit.hbm.xml n'existe pas alors qu'il existe dans le répertoire web-inf. j'ai esseyé des chose comme classpathroduit.hbm.xml ou /WEB-INF/Produit.hbm.xml mais toujours la même erreur.
    Merci d'avance pour vos réponses.

  2. #2
    Membre confirmé
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    149
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 149
    Par défaut
    Si ton fichier hbm.xml est bien dans le répertoire WEB-INF
    /WEB-INF/Produit.hbm.xml
    devrait marcher. Essaie de faire un clean et build du projet après la modification.

    Personnellement, je place le fichier hbm dans le même package que la classe avec laquelle il est mappé. J'utilise la propriété "mappingLocations" et je pointe vers ce fichier

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    <property name="mappingLocations">
            <list>
                <value>classpath*:/toto/titi/tata/*.hbm.xml</value>
            </list>
        </property>
    /toto/titi/tata étant le package où se trouve ma classe "Produit". Et ça marche très bien

  3. #3
    Candidat au Club
    Inscrit en
    Septembre 2009
    Messages
    3
    Détails du profil
    Informations forums :
    Inscription : Septembre 2009
    Messages : 3
    Par défaut
    Merci pour ton aide grospatapouf sa passe maintenant mais il me dit que Produit n'est pas mapped(Produit est la classe qui est mappé). J'ai deplacé mes fichiers dans un package et j'ai mis dans mappinglocations
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    classpath*:/akatsuki/domain/mappinghibernate/*.hbm.xml
    /toto/titi/tata étant le package où se trouve ma classe "Produit". Et ça marche très bien
    au fait dans ton package se sont les fichiers mappings ou ta classe ou les deux.

  4. #4
    Membre confirmé
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    149
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 149
    Par défaut
    J'ai l'impression que ta requête n'est pas bonne mais faudrait un peu plus d'info. Comment s'appelle ta table? J'imagine que ta classe s'appelle 'Produit'. Comment fais-tu la requête? Attention elle doit être du genre
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    "from Produit p where p.produitId ..."
    où Produit est la classe (et non la table) et produitId une propriété de cette classe.

    Pour me retrouver facilement je mets la classe et le fichier mapping dans le même package.

  5. #5
    Candidat au Club
    Inscrit en
    Septembre 2009
    Messages
    3
    Détails du profil
    Informations forums :
    Inscription : Septembre 2009
    Messages : 3
    Par défaut
    voici ma classe Dao avec la requête:
    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
     
    /*
     *
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    package akatsuki.domain.repositryimpl;
    import akatsuki.domain.model.Produit;
    import akatsuki.domain.repositry.ProductDao;
    import java.io.FileWriter;
    import java.sql.SQLException;
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.List;
    import org.hibernate.HibernateException;
    import org.hibernate.Query;
    import org.hibernate.Session;
    import org.hibernate.SessionFactory;
    import org.hibernate.Transaction;
    import org.springframework.orm.hibernate3.HibernateCallback;
    import org.springframework.orm.hibernate3.HibernateTemplate;
     
    //import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
    /**
     *
     * @author hamza
     */
    public class ProduitDaoHibernate   implements ProductDao{
     
        private HibernateTemplate hibernateTemplate;
     
        public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
            this.hibernateTemplate = hibernateTemplate;
        }
     
        public List<Produit> getProduits() {
            HibernateCallback callback = new HibernateCallback() {
     
                public Object doInHibernate(Session sessionHibernate) throws HibernateException, SQLException {
                    Transaction tx= sessionHibernate.beginTransaction();
                    List<Produit>lst;
                    lst=new ArrayList<Produit>();
                    Query req = sessionHibernate.createQuery("select id,nom from Produit");
                    for(Iterator it = req.iterate();it.hasNext();){
                        Produit p = new Produit();
                        Object[]ligne=(Object[])it.next();
                        p.setId(String.valueOf(ligne[0]));
                        p.setNom(String.valueOf(ligne[1]));
                        lst.add(p);
                    }
                    tx.commit();
                    return lst;
                }
            };
     
     
            return (List<Produit>)hibernateTemplate.execute(callback);
        }
     
     
    }

  6. #6
    Membre confirmé
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    149
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 149
    Par défaut
    Tu peux poster la trace complète ainsi que le fichier de mapping? Une autre question, est-ce que tu utilise des annotations?

Discussions similaires

  1. Probleme avec la propriete CommandText-ProcedureStockée
    Par o_live dans le forum C++Builder
    Réponses: 1
    Dernier message: 15/05/2009, 15h22
  2. Probleme avec binding d'une propriete
    Par Seth77 dans le forum Windows Forms
    Réponses: 1
    Dernier message: 13/03/2009, 16h07
  3. Probleme avec un propriete d'un UserControl dans le designer
    Par Seth77 dans le forum Windows Forms
    Réponses: 2
    Dernier message: 06/01/2009, 18h48
  4. Réponses: 7
    Dernier message: 04/10/2007, 11h31
  5. [VBA-E] Probleme avec proprièté formula
    Par Mut dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 06/11/2006, 22h33

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