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 :

[Ibatis] Column not found [Data]


Sujet :

Spring Java

  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Août 2005
    Messages
    10
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 10
    Par défaut [Ibatis] Column not found
    Bonjour,

    Je travaille avec Websphère 5.1 et une base MySql.

    je suis en train de tester une nouvelle requête assez simple avec "sqlMap" qui récupère un ou plusieurs enregistrements en lui passant un id et une date.
    J'avais déjà fait une première requête getAll() qui fonctionne très bien et pour faire cette nouvelle requête je dois ajouter une propriété "dateCertifNir" dans le resultMap de mon fichier d'ordres SQL et apparemment ca coince, j'ai l'erreur quivante :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Error 500: ; nested exception is: org.springframework.jdbc.BadSqlGrammarException: SqlMapClient operation; bad SQL grammar []; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException: --- The error occurred in fr/canam/rniam/ibatis/config/demandes-mysql.xml. --- The error occurred while applying a result map. --- Check the demandes.map. --- Check the result mapping for the 'dateCertifNir' property. --- Cause: java.sql.SQLException: Column 'date_certif_nir' not found. Caused by: java.sql.SQLException: Column 'date_certif_nir' not found.
    Voici mon fichier xml :

    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
    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd">
    <!-- Fichiers contenant les ordres SQL -->
    <sqlMap>
    <typeAlias alias="demandes.classe" type="fr.canam.rniam.entites.Demandes"/>
    	<resultMap id="demandes.map" class="fr.canam.rniam.entites.Demandes">
    		<result property="strTypeDemande" column="type_demande"/>
    		<result property="strEtatDemande" column="etat_demande"/> 
    		<result property="dateEmisDemande" column="date_demande"/>
    		<result property="dateRecepReponse" column="date_reponse"/>
    		<result property="strNir" column="nir_demande"/>
    		<result property="dateCertifNir" column="date_certif_nir"/>
    		<result property="strNom" column="nom_demande"/>
    		<result property="strPrenom" column="prenom_demande"/>	
    		<!--<result property="dateNaiss" column="date_naissance_demande"/>-->
    	</resultMap>
    	<!-- liste des demandes -->
    	<select id="demandes.getAll" resultMap="demandes.map">
    		SELECT TYPE_DEMANDE, ETAT_DEMANDE, DATE_DEMANDE, DATE_REPONSE, NIR_DEMANDE, NOM_DEMANDE, PRENOM_DEMANDE FROM DEMANDE
    	</select>
    	<!-- liste des demandes par Nir et dateCertif-->
    	<select id="demandes.getDemandesNir" resultMap="demandes.map" parameterClass="demandes.classe" remapResults="true">
    		SELECT TYPE_DEMANDE, ETAT_DEMANDE, DATE_DEMANDE, DATE_REPONSE, NIR_DEMANDE, NOM_DEMANDE, PRENOM_DEMANDE FROM DEMANDE WHERE NIR_DEMANDE=#strNir# AND DATE_CERTIF_NIR=#dateCertifNir#
    	</select>
    </sqlMap>
    La requête que je veux exécuter est demandes.getDemandesNir

    Voici le code de ma méthode dans ma classe DaoImpl :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    	public Collection getDemandesNir(String strNir, Timestamp dateCertif) {
    		// TODO Raccord de méthode auto-généré
    		Demandes demandes = new Demandes();
    		demandes.setStrNir(strNir);
    		demandes.setDateCertifNir(dateCertif);
    		return getSqlMapClientTemplate().queryForList("demandes.getDemandesNir",demandes);
    	}
    et enfin mon objet métier demandes :

    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
    public class Demandes {
     
    	private String strTypeDemande;
    	private String strEtatDemande;
    	private Timestamp dateEmisDemande;
    	private Timestamp dateRecepReponse;
    	private Timestamp dateCertifNir;
    	private Timestamp dateNaiss;
     
    	private String strNir;
    	private String strNom;
    	private String strPrenom;
     
    	public Demandes() {
    	}
     
    	public Demandes(
    		String strTypeDemande,
    		String strEtatDemande,
    		Timestamp dateEmisDemande,
    		Timestamp dateRecepReponse,
    		String strNir,
    		String strNom,
    		String strPrenom
    		){
    		this.strTypeDemande = strTypeDemande;
    		this.strEtatDemande = strEtatDemande;
    		this.dateEmisDemande = dateEmisDemande;
    		this.dateRecepReponse = dateRecepReponse;
    		this.strNir = strNir;
    		this.strNom = strNom;
    		this.strPrenom = strPrenom;
    	}
     
    	/**
             * @return
             */
    	public Timestamp getDateEmisDemande() {
    		return dateEmisDemande;
    	}
     
    	/**
             * @return
             */
    	public Timestamp getDateRecepReponse() {
    		return dateRecepReponse;
    	}
     
    	/**
             * @return
             */
    	public String getStrEtatDemande() {
    		return strEtatDemande;
    	}
     
    	/**
             * @return
             */
    	public String getStrNir() {
    		return strNir;
    	}
     
    	/**
             * @return
             */
    	public String getStrNom() {
    		return strNom;
    	}
     
    	/**
             * @return
             */
    	public String getStrPrenom() {
    		return strPrenom;
    	}
     
    	/**
             * @return
             */
    	public String getStrTypeDemande() {
    		return strTypeDemande;
    	}
     
    	/**
             * @param timestamp
             */
    	public void setDateEmisDemande(Timestamp timestamp) {
    		dateEmisDemande = timestamp;
    	}
     
    	/**
             * @param timestamp
             */
    	public void setDateRecepReponse(Timestamp timestamp) {
    		dateRecepReponse = timestamp;
    	}
     
    	/**
             * @param string
             */
    	public void setStrEtatDemande(String string) {
    		strEtatDemande = string;
    	}
     
    	/**
             * @param string
             */
    	public void setStrNir(String string) {
    		strNir = string;
    	}
     
    	/**
             * @param string
             */
    	public void setStrNom(String string) {
    		strNom = string;
    	}
     
    	/**
             * @param string
             */
    	public void setStrPrenom(String string) {
    		strPrenom = string;
    	}
     
    	/**
             * @param string
             */
    	public void setStrTypeDemande(String string) {
    		strTypeDemande = string;
    	}
     
    	/**
             * @return
             */
    	public Timestamp getDateCertifNir() {
    		return dateCertifNir;
    	}
     
    	/**
             * @param timestamp
             */
    	public void setDateCertifNir(Timestamp timestamp) {
    		dateCertifNir = timestamp;
    	}
     
    	/**
             * @return
             */
    	public Timestamp getDateNaiss() {
    		return dateNaiss;
    	}
     
    	/**
             * @param timestamp
             */
    	public void setDateNaiss(Timestamp timestamp) {
    		dateNaiss = timestamp;
    	}
     
    	}
    Je précise que j'ai vérifié les concordances des noms avec la table "demande" et ca colle.

  2. #2
    Membre averti
    Profil pro
    Inscrit en
    Août 2005
    Messages
    10
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 10
    Par défaut
    Apparemment si je passe uniquement le paramètre id, que je supprime le critère de recherche sur la date dans la requête et que je met en commentaire la ligne

    <result property="dateCertifNir" column="date_certif_nir"/>

    du fichier de mapping cela fonctionne.

    Ce qui veux dire que celà vient de mon champ date qui est un Timestamp dans la base et je l'envoie bien en tant que Timestamp.

    Voilà un peu plus d'infos, merci de m'aider

  3. #3
    Membre confirmé Avatar de tnodev
    Profil pro
    SSSSS
    Inscrit en
    Mai 2005
    Messages
    182
    Détails du profil
    Informations personnelles :
    Âge : 53
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : SSSSS

    Informations forums :
    Inscription : Mai 2005
    Messages : 182
    Par défaut
    Bonjour

    l'origine de l'erreur vient du fait que tu ne récupéres pas la colonne date_certif_nir dans ta requête SQL...
    Donc, il rouspéte car dans le resultMap, tu associes cette colonne à une propriété qu'il ne trouve donc pas

  4. #4
    Membre averti
    Profil pro
    Inscrit en
    Août 2005
    Messages
    10
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 10
    Par défaut
    Voilà, je reviens sur mon projet et je suis passé à une base Oracle 8i.
    Le problème persiste.
    Il ne manque pas de colonne dans ma requête.
    Lorsque j'exécute la requête en lui passant en paramètre un champ de type String ou Numérique tout va bien mais lorsque je passe un champ de type date ou timestamp rien na va plus.

    Je me demandais si quelqu'un connaissait les TypeHandler et si cela pouvait résoudre mon problème ?

  5. #5
    Membre averti
    Profil pro
    Inscrit en
    Août 2005
    Messages
    10
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 10
    Par défaut
    J'ai oublié une info, l'erreur est un peu différente :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Error 500: ; nested exception is: org.springframework.jdbc.BadSqlGrammarException: SqlMapClient operation; bad SQL grammar []; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException: --- The error occurred in fr/canam/rniam/ibatis/config/demandes.xml. --- The error occurred while applying a result map. --- Check the demandes.map. --- Check the result mapping for the 'dateCertifNir' property. --- Cause: java.sql.SQLException: Nom de colonne non valide Caused by: java.sql.SQLException: Nom de colonne non valide

  6. #6
    Membre Expert Avatar de KiLVaiDeN
    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    2 870
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2003
    Messages : 2 870
    Par défaut
    Salut,

    Si il manque ta colonne dans tes requêtes, je les ai modifié :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    	<!-- liste des demandes -->
    	<select id="demandes.getAll" resultMap="demandes.map">
    		SELECT TYPE_DEMANDE, ETAT_DEMANDE, DATE_DEMANDE, DATE_REPONSE, NIR_DEMANDE, NOM_DEMANDE, PRENOM_DEMANDE, DATE_CERTIF_NIR FROM DEMANDE
    	</select>
    	<!-- liste des demandes par Nir et dateCertif-->
    	<select id="demandes.getDemandesNir" resultMap="demandes.map" parameterClass="demandes.classe" remapResults="true">
    		SELECT TYPE_DEMANDE, ETAT_DEMANDE, DATE_DEMANDE, DATE_REPONSE, NIR_DEMANDE, NOM_DEMANDE, PRENOM_DEMANDE, DATE_CERTIF_NIR FROM DEMANDE WHERE NIR_DEMANDE=#strNir# AND DATE_CERTIF_NIR=#dateCertifNir#
    	</select>

  7. #7
    Membre averti
    Profil pro
    Inscrit en
    Août 2005
    Messages
    10
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 10
    Par défaut
    Effectivement, merci beaucoup.
    En fait je n'avais pas compris que le result-map ne devai contenir que les champs du select alors j'y avais également mis les champs que je voulais passer en paramètre.

    Merci encore

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

Discussions similaires

  1. mysql5 : column not found avec jdbc
    Par julien20vt dans le forum JDBC
    Réponses: 0
    Dernier message: 08/03/2011, 11h26
  2. Réponses: 4
    Dernier message: 13/11/2010, 17h35
  3. [Hibernate 2.1.6] SQLException: Column not found
    Par GyZmoO dans le forum Hibernate
    Réponses: 0
    Dernier message: 27/10/2010, 18h13
  4. Zend DB | Column not found
    Par Exo dans le forum Zend_Db
    Réponses: 1
    Dernier message: 28/09/2008, 13h15
  5. Réponses: 5
    Dernier message: 12/12/2005, 13h13

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