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 :

Erreur "Table is not mapped"


Sujet :

Spring Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Août 2006
    Messages
    229
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Côte d'Ivoire

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Août 2006
    Messages : 229
    Par défaut Erreur "Table is not mapped"
    Bonjour,

    Je suis nouveau développeur Spring et j'essaie de mettre en place une petite application console.

    Voici mon fichier de configuration : SpringXMLConfig:
    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
    <?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:context="http://www.springframework.org/schema/context"
           xmlns:flow="http://www.springframework.org/schema/webflow-config"
           xmlns:jms="http://www.springframework.org/schema/jms"
           xmlns:jee="http://www.springframework.org/schema/jee"
           xmlns:lang="http://www.springframework.org/schema/lang"
           xmlns:osgi="http://www.springframework.org/schema/osgi"
           xmlns:tx="http://www.springframework.org/schema/tx"
           xmlns:util="http://www.springframework.org/schema/util"
           xmlns:p="http://www.springframework.org/schema/p"
     
           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.6.SEC01.xsd
              http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.6.SEC01.xsd
              http://www.springframework.org/schema/webflow-config http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd
              http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-2.5.6.SEC01.xsd
              http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.6.SEC01.xsd
              http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.5.6.SEC01.xsd
              http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi-2.5.6.SEC01.xsd
              http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.6.SEC01.xsd
              http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
     
        <!-- couches applicatives -->
        <bean id="dao" class="Dao.dao" />
         <bean id="service" class="Service.service">
            <property name="dao" ref="dao" />
        </bean>
     
    <!-- la source de donnéees DBCP -->
        <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" destroy-method="close">
            <property name="driverClassName" value="com.mysql.jdbc.Driver" />
            <property name="url" value="jdbc:mysql://localhost:3306/gest_labo" />
            <property name="username" value="root" />
            <property name="password" value="root" />
        </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.HibernateJpaVendorAdapter">
                    <!--
                        <property name="showSql" value="true" />
                    -->
                                    <property name="databasePlatform" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
                    <property name="generateDdl" value="true" />
     
                </bean>
            </property>
            <property name="loadTimeWeaver">
                <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
            </property>
     
     
        </bean>
     
     
     
          <!-- Le gestionnaire de transaction -->
        <tx:annotation-driven transaction-manager="txManager"/>
        <bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
            <property name="entityManagerFactory" ref="entityManagerFactory"/>
        </bean>
     
        <!-- traduction des exceptions -->
        <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
     
        <!-- persistence -->
        <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
     
    </beans>
    Et voici le code de ma classe TClient:

    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
    package metier;
     
    import java.io.Serializable;
    import javax.persistence.Basic;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.NamedQueries;
    import javax.persistence.NamedQuery;
    import javax.persistence.Table;
     
    /**
     *
     * @author SYLLA
     */
    @Entity
    @Table(name = "t_client", catalog = "gest_labo", schema = "")
    @NamedQueries({
        @NamedQuery(name = "TClient.findAll", query = "SELECT t FROM TClient t"),
        @NamedQuery(name = "TClient.findById", query = "SELECT t FROM TClient t WHERE t.id = :id"),
        @NamedQuery(name = "TClient.findByNom", query = "SELECT t FROM TClient t WHERE t.nom = :nom"),
        @NamedQuery(name = "TClient.findByDescription", query = "SELECT t FROM TClient t WHERE t.description = :description")})
    public class TClient implements Serializable {
     
        private static final long serialVersionUID = 1L;
        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        @Basic(optional = false)
        @Column(name = "Id", nullable = false)
        private Integer id;
        @Basic(optional = false)
        @Column(name = "Nom", nullable = false, length = 255)
        private String nom;
        @Basic(optional = false)
        @Column(name = "Description", nullable = false, length = 255)
        private String description;
     
        public TClient() {
        }
     
        public TClient(Integer id) {
            this.id = id;
        }
     
        public TClient(Integer id, String nom, String description) {
            this.id = id;
            this.nom = nom;
            this.description = description;
        }
     
        public Integer getId() {
            return id;
        }
     
        public void setId(Integer id) {
            this.id = id;
        }
     
        public String getNom() {
            return nom;
        }
     
        public void setNom(String nom) {
            this.nom = nom;
        }
     
        public String getDescription() {
            return description;
        }
     
        public void setDescription(String description) {
            this.description = description;
        }
     
        @Override
        public int hashCode() {
            int hash = 0;
            hash += (id != null ? id.hashCode() : 0);
            return hash;
        }
     
        @Override
        public boolean equals(Object object) {
            // TODO: Warning - this method won't work in the case the id fields are not set
            if (!(object instanceof TClient)) {
                return false;
            }
            TClient other = (TClient) object;
            if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
                return false;
            }
            return true;
        }
     
        @Override
        public String toString() {
            return "virtuaschool.metier.TClient[id=" + id + "]";
        }
     
    }
    et voici l'appel que je fais dans ma fonction main()
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
            ApplicationContext ctx = new ClassPathXmlApplicationContext("SpringXMLConfig.xml");
            // couche service
                service = (IService) ctx.getBean("service");
                    service.getAll();
    Et maintenant quand j'exécute mon programme le message d'erreur suivant:
    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
     TClient is not mapped [select p from TClient p][/quote][quote]
    run:
    INFO - AbstractApplicationContext.prepareRefresh(412) | Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@12a3793: display name [org.springframework.context.support.ClassPathXmlApplicationContext@12a3793]; startup date [Mon Jun 06 14:36:43 GMT 2011]; root of context hierarchy
    INFO - XmlBeanDefinitionReader.loadBeanDefinitions(323) | Loading XML bean definitions from class path resource [SpringXMLConfig.xml]
    INFO - AbstractApplicationContext.obtainFreshBeanFactory(427) | Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext@12a3793]: org.springframework.beans.factory.support.DefaultListableBeanFactory@1a68ef9
    INFO - DriverManagerDataSource.setDriverClassName(155) | Loaded JDBC driver: com.mysql.jdbc.Driver
    INFO - AbstractApplicationContext$BeanPostProcessorChecker.postProcessAfterInitialization(1197) | Bean 'dataSource' is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
    INFO - AbstractApplicationContext$BeanPostProcessorChecker.postProcessAfterInitialization(1197) | Bean 'org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter#b03be0' is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
    INFO - AbstractApplicationContext$BeanPostProcessorChecker.postProcessAfterInitialization(1197) | Bean 'org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver#2af081' is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
    INFO - LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(221) | Building JPA container EntityManagerFactory for persistence unit 'VirtuaSchoolPU'
    INFO - AbstractApplicationContext$BeanPostProcessorChecker.postProcessAfterInitialization(1197) | Bean 'entityManagerFactory' is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
    INFO - DefaultListableBeanFactory.preInstantiateSingletons(414) | Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1a68ef9: defining beans [dao,service,client,dataSource,entityManagerFactory,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,txManager,org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0,org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor#0]; root of factory hierarchy
    Exception in thread "main" java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: TClient is not mapped [select p from TClient p]
            at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:634)
            at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:95)
    J'ai vraiment besoin de comprendre comment faire le mapping Spring dans le fichier de configuration.

    Merci d'avance!

  2. #2
    Membre éclairé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Août 2006
    Messages
    229
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Côte d'Ivoire

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Août 2006
    Messages : 229
    Par défaut
    Je tiens à préciser que je développe sous NetBeans 9.6.1;

    Message d'erreur :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    TClient is not mapped [select p from TClient p]
    Merci pour votre aide.

  3. #3
    Membre expérimenté Avatar de aymen83
    Inscrit en
    Décembre 2007
    Messages
    271
    Détails du profil
    Informations forums :
    Inscription : Décembre 2007
    Messages : 271
    Par défaut
    il s'agit d'une erreur de config de ton
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    il doit être au courant de tes classe annotée comme étant des entités. Il doit y avoir une proprieté comme annotatedClass ou qlq chose comme ça et ou tu déclare tes entités.

  4. #4
    Membre éprouvé Avatar de juridakus
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2008
    Messages
    82
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Maroc

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2008
    Messages : 82
    Par défaut
    Salut,
    comme le dit aymen83, tu as peut être oublié de lui où trouver tes classes annotées. Pour cela tu peut ajouter ceci:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    <context:component-scan base-package="metier"/>
    <context:annotation-config/>
    Espérant que cela t'aide.

  5. #5
    Membre éclairé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Août 2006
    Messages
    229
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Côte d'Ivoire

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Août 2006
    Messages : 229
    Par défaut
    Quand j'ajoute ces lignes voici le message d'erreur que j'obtiens:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    INFO - XmlBeanDefinitionReader.loadBeanDefinitions(323) | Loading XML bean definitions from class path resource [SpringXMLConfig.xml]
    WARN - SimpleSaxErrorHandler.warning(47) | Ignored XML validation warning
    org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/context/spring-context-2.5.6.SEC01.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
    Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 26 in XML document from class path resource [SpringXMLConfig.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'context:component-scan'.

  6. #6
    Membre expérimenté Avatar de aymen83
    Inscrit en
    Décembre 2007
    Messages
    271
    Détails du profil
    Informations forums :
    Inscription : Décembre 2007
    Messages : 271
    Par défaut
    il te manque le namespace dans le header de ton fichier de config
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    xmlns:context="http://www.springframework.org/schema/context"
    et
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    xsi:schemaLocation="http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"
    bien sûr la version du xsd à utiliser dépend de la version spring que tu utilise

Discussions similaires

  1. QuerySyntaxException: [table is not mapped]
    Par lgcaro29 dans le forum JPA
    Réponses: 2
    Dernier message: 05/01/2015, 11h08
  2. Réponses: 1
    Dernier message: 20/04/2009, 13h49
  3. QuerySyntaxException: [table is not mapped]
    Par liquideshark dans le forum Hibernate
    Réponses: 3
    Dernier message: 16/07/2008, 12h01
  4. supprimer une table qui a des quotes dans son nom
    Par kleenex dans le forum Access
    Réponses: 2
    Dernier message: 17/10/2005, 16h03

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