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 :

Java et le framework hibernate


Sujet :

Hibernate Java

  1. #1
    Candidat au Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Avril 2015
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 33
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Avril 2015
    Messages : 5
    Points : 4
    Points
    4
    Par défaut Java et le framework hibernate
    bonjour à tous je débute avec java et j'aimerai développer une application des gestion des étudiants avec leurs notes ,pour ça j'ai créer les classes et les fichiers de mapping ,A l’exécution on m'affiche [BUILD SUCCESSFUL (total time: 2 seconds)]mais rien n'est inséré dans ma base mysql
    voici le code de la classe étudiant
    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
     
     
    package bean;
     
    import java.util.Date;
    import java.util.HashSet;
    import java.util.Set;
     
    public class Etudiant {
     
        private String numinscription;
        private String nom;
        private String prenom;
        private Date dateNaissance;
        private String lieuNaissance;
        private String Sexe;
        private String Nationalité;
        private int année;
        private boolean repetitif;
        private Set<Note> noteGlobale = new HashSet<Note>();
     
        public Etudiant(){}
     
        public Etudiant(String nom, String prenom) {
            this.nom = nom;
            this.prenom = prenom;
        }
     
     
        public Etudiant(String numinscription, String nom, String prenom, Date dateNaissance, String lieuNaissance, String Sexe, String Nationalité, int année, boolean repetitif) {
            this.numinscription = numinscription;
            this.nom = nom;
            this.prenom = prenom;
            this.dateNaissance = dateNaissance;
            this.lieuNaissance = lieuNaissance;
            this.Sexe = Sexe;
            this.Nationalité = Nationalité;
            this.année = année;
            this.repetitif = repetitif;
        }
     
        public boolean isRepetitif() {
            return repetitif;
        }
     
        public void setRepetitif(boolean repetitif) {
            this.repetitif = repetitif;
        }
     
     
        public String getNuminscription() {
            return numinscription;
        }
     
        public String getNom() {
            return nom;
        }
     
        public String getPrenom() {
            return prenom;
        }
     
        public Date getDateNaissance() {
            return dateNaissance;
        }
     
        public String getLieuNaissance() {
            return lieuNaissance;
        }
     
        public String getSexe() {
            return Sexe;
        }
     
        public String getNationalité() {
            return Nationalité;
        }
     
        public int getAnnée() {
            return année;
        }
     
        public Set<Note> getNoteGlobale() {
            return noteGlobale;
        }
     
        public void setNuminscription(String numinscription) {
            this.numinscription = numinscription;
        }
     
        public void setNom(String nom) {
            this.nom = nom;
        }
     
        public void setPrenom(String prenom) {
            this.prenom = prenom;
        }
     
        public void setDateNaissance(Date dateNaissance) {
            this.dateNaissance = dateNaissance;
        }
     
        public void setLieuNaissance(String lieuNaissance) {
            this.lieuNaissance = lieuNaissance;
        }
     
        public void setSexe(String Sexe) {
            this.Sexe = Sexe;
        }
     
        public void setNationalité(String Nationalité) {
            this.Nationalité = Nationalité;
        }
     
        public void setAnnée(int année) {
            this.année = année;
        }
     
        public void setNoteGlobale(Set<Note> noteGlobale) {
            this.noteGlobale = noteGlobale;
        }
     
        public void setDateNaissance(String string) {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
     
     
     
    }

    et le code de la classe note
    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
     
    package bean;
    public class Note {
        private int numNote;
        private float note;
     
        public Note() {
        }
    public Note(int numNote, float note) {
            this.numNote = numNote;
            this.note = note;
        }
     
        public int getNumNote() {
            return numNote;
        }
     
        public float getNote() {
            return note;
        }
     
        public void setNumNote(int numNote) {
            this.numNote = numNote;
        }
     
        public void setNote(float note) {
            this.note = note;
        }
     
     
    }
    les fichiers de mapping
    etudiant.hbm.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
     
    <?xml version="1.0" encoding="UTF-8"?>
    <hibernate-mapping>
        <class name = "bean.Etudiant" table = "etudiants">
            <id name = "numinscription" column = "num_inscription">      
            </id>
            <property name = "nom" column = "Nom">      
            </property>
            <property name = "prenom" column = "Prenom">      
            </property>
            <property name = "dateNaissance" column = "date_naissance">      
            </property>
            <set name="noteglobale" cascade = "all">
                <key column="numNote"/>
                <one-to-many class = "bean.Note"/>
            </set>
     
        </class>
    </hibernate-mapping>
    et note.hbm.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
     
    <?xml version="1.0" encoding="UTF-8"?>
    <hibernate-mapping>
        <class name = "bean.Note" table = "notes">
            <property name = "valNote" column = "valeure">      
            </property>
            <property name = "semestre" column = "num_semestre">      
            </property>
            <property name = "designmodule" column = "design_module">      
            </property>
            <property name = "année" column = "année_étude">      
            </property>
        </class>
    </hibernate-mapping>
    Merci d'avance pour l'intérêt que vous porterez.

  2. #2
    Membre éclairé

    Profil pro
    Inscrit en
    Janvier 2009
    Messages
    461
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2009
    Messages : 461
    Points : 894
    Points
    894
    Billets dans le blog
    5
    Par défaut
    Je recommande d'utiliser JPA, dont Hibernate est maintenant une implémentation, et surtout de passer par les annotations (et non pas les fichier XML).

    On n'utilise pas les fichier XMl depuis plus de 10 ans!

  3. #3
    Modérateur
    Avatar de OButterlin
    Homme Profil pro
    Inscrit en
    Novembre 2006
    Messages
    7 310
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 7 310
    Points : 9 522
    Points
    9 522
    Billets dans le blog
    1
    Par défaut
    Citation Envoyé par PhilippeGibault Voir le message
    On n'utilise pas les fichier XMl depuis plus de 10 ans!
    Euh, c'est excessif comme commentaire, même dans ce contexte

    On utilise xml si on a des adaptations de mapping qui dépendent du paramétrage d'une base de données.
    Dans le cadre d'une application qui serait vendue à plusieurs clients et plusieurs base de données avec des spécificités comme (par exemple) les noms en majuscules ou minuscules ou mixées aboutissant au mêmes classes d'utilisation...

    Si par contre l'environnement est connu et fixe, alors il est préférable (et certainement plus clair) d'utiliser les annotations (on a les informations de structure et de cible au même endroit).
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

Discussions similaires

  1. Réponses: 0
    Dernier message: 11/05/2009, 18h19
  2. jade (java agent developement framework)
    Par ilhemo dans le forum Programmation par agent
    Réponses: 0
    Dernier message: 09/05/2009, 20h10
  3. Difference entre Entity Framework / Hibernate.
    Par gregb34 dans le forum Framework .NET
    Réponses: 22
    Dernier message: 04/04/2009, 13h42
  4. Réponses: 9
    Dernier message: 30/12/2008, 11h47
  5. Réponses: 0
    Dernier message: 13/10/2008, 17h39

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