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

Hibernate Java Discussion :

relation many to one


Sujet :

Hibernate Java

  1. #1
    Membre habitué
    Avatar de CPI_en_mousse
    Homme Profil pro
    Développeur Java
    Inscrit en
    Avril 2006
    Messages
    332
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2006
    Messages : 332
    Points : 168
    Points
    168
    Par défaut relation many to one
    j'ai la relation many-to-one suivante :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <many-to-one name="jobTitle" column="jT_ID" class="be.qspin.qats.entities.JobTitle" cascade="none" not-null="false"/>
    qui se trouve dans le fichier applicant.hbm.xml

    l'attribut name="jobTitle" correspond au nom de l'attribut qui sera dans la classe applicant?
    Quant à l'attribut column="jT_ID" correspond au nom de la colonne dans la table applicant?

    j'ai tous bon ou bien je me trompe?

  2. #2
    Membre habitué
    Avatar de CPI_en_mousse
    Homme Profil pro
    Développeur Java
    Inscrit en
    Avril 2006
    Messages
    332
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2006
    Messages : 332
    Points : 168
    Points
    168
    Par défaut
    l'attribut column="jT_ID" doit il avoir le meme non que dans la classe jobTitle?

    d'ou peu provenir l'erreur suivante?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Caused by: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown column 'this_.JT_ID' in 'field list'
    applicant.hbm
    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
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
     
    <!--
        Document   : Applicant.hbm.xml
        Created on : 25 avril 2007, 10:14
        Author     : florian
        Description:
            Mapping fot the applicant entities
    -->
     
     
    <hibernate-mapping default-lazy="false">
        <class name="be.qspin.qats.entities.Applicant" table="APPLICANTS">
            <meta attribute="class-description">
                Define an "Applicant" entity.
                @author Florian Guillemotte
                @author fguillemotte@gmail.com
            </meta>
            <id name="id" type="integer" column="ID">
                <generator class="increment">
                </generator>            
            </id>
            <property name="lastname" type="string" not-null="true">
                <column name="LASTNAME" length="20" not-null="true"/>
            </property>
            <property name="firstname" type="string" not-null="true">
                <column name="FIRSTNANE" length="20" not-null="true"/>
            </property>
            <property name="gender" type="string" not-null="true">
                <column name="GENDER" length="20" not-null="true"/>
            </property>        
            <property name="birthday" type="timestamp" not-null="false">
                <column name="BIRTHDAY" length="20" not-null="false"/>
            </property>
            <property name="nationality" type="string" not-null="true">
                <column name="NATIONALITY" length="20" not-null="true"/>
            </property>
            <property name="address" type="string" not-null="true">
                <column name="ADDRESS" length="20" not-null="true"/>
            </property>
            <property name="PC" type="string" not-null="true">
                <column name="PC" length="20" not-null="true"/>
            </property>        
            <property name="city" type="string" not-null="true">
                <column name="CITY" length="20" not-null="true"/>
            </property>    
            <property name="country" type="string" not-null="true">
                <column name="COUNTRY" length="20" not-null="true"/>
            </property>  
            <property name="phone" type="string" not-null="true">
                <column name="PHONE" length="20" not-null="true"/>
            </property>    
            <property name="gsm" type="string" not-null="true">
                <column name="GSM" length="20" not-null="true"/>
            </property>  
            <property name="email" type="string" not-null="true">
                <column name="EMAIL" length="20" not-null="true"/>
            </property>   
            <property name="interest" type="string" not-null="true">
                <column name="INTEREST" length="1" not-null="true"/>
            </property>  
     
            <many-to-one name="jobTitle" column="JT_ID" class="be.qspin.qats.entities.JobTitle" cascade="none" not-null="false"/>
     
        </class>
    </hibernate-mapping>
    et jobTitle.hbm
    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
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
     
    <!--
        Document   : Evaluation.hbm.xml
        Created on : 24 mai 2007, 16:29
        Author     : florian
        Description:
            Purpose of the document follows.
    -->
     
    <hibernate-mapping default-lazy="false">
        <class name="be.qspin.qats.entities.JobTitle" table="JOBTITLES">
            <meta attribute="class-description">
                Define an "Job Title" entity.
                @author Florian Guillemotte
                @author fguillemotte@gmail.com
            </meta>
            <id name="id" type="integer" column="JT_ID">
                <generator class="increment">
                </generator>            
            </id>
            <property name="title" type="string" not-null="true">
                <column name="TITLE" length="50" not-null="true"/>
            </property>
     
        </class>
    </hibernate-mapping>

  3. #3
    Expert confirmé
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 274
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 274
    Points : 4 141
    Points
    4 141
    Par défaut
    Tu as bien vu :
    -name : pour le nom de la propriété
    -column : pour le nom de ta colonne en base

    L'attribut name doit avoir le même nom que ta propriété java de ta classe.

  4. #4
    Membre régulier Avatar de KneXtasY
    Profil pro
    Inscrit en
    Mars 2004
    Messages
    121
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2004
    Messages : 121
    Points : 109
    Points
    109
    Par défaut
    Tout semble correct.

    Les colonnes "jT_ID" de APPLICANTS et de JOBTITLES ont bien le même type en base ?

  5. #5
    Membre habitué
    Avatar de CPI_en_mousse
    Homme Profil pro
    Développeur Java
    Inscrit en
    Avril 2006
    Messages
    332
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2006
    Messages : 332
    Points : 168
    Points
    168
    Par défaut
    C'est résolu
    j'avais modifier ma base de données et lorsque j'executais mon script pour recharger les données fixes, ca me remettai la DBB a l'ancienne. erreur stupide

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

Discussions similaires

  1. Réponses: 1
    Dernier message: 02/10/2007, 10h12
  2. relation many-to-one avec clefs composites
    Par Foub dans le forum Hibernate
    Réponses: 2
    Dernier message: 27/09/2007, 14h33
  3. [ASP.NET 2.0] DataBinding et relation Many to one
    Par Mandotnet dans le forum ASP.NET
    Réponses: 1
    Dernier message: 18/01/2007, 13h48
  4. Relation Many-to-One dans une application JSF
    Par KooKoolen dans le forum JSF
    Réponses: 1
    Dernier message: 27/12/2006, 14h13
  5. Hibernate : suppression sur relation many to one
    Par taf dans le forum Hibernate
    Réponses: 1
    Dernier message: 23/05/2006, 13h08

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