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 :

OnetoOne hibernate Spring


Sujet :

Hibernate Java

  1. #1
    Membre régulier
    Profil pro
    Inscrit en
    Février 2007
    Messages
    120
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2007
    Messages : 120
    Points : 83
    Points
    83
    Par défaut OnetoOne hibernate Spring
    Bonjour,

    En fait mon problème est simple mais je n'arrive pas à le mettre en place.

    En fait j'ai des evenements stockés en base de données avec une colonne client qui contient l'id du client concerné correspondant à la table clients.

    J'ai une clé étrangère encore la colonne client de la table [events] et id_client de la table [clients]

    Et en fait, j'aimerai simplement récupérer un objet client correspondant à l'événement concerné.

    Voici mes classes

    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
    @Entity
    @Table(name = "events", catalog = "calendar")
    public class Events implements java.io.Serializable {
     
        private Integer idEvent;
        private int user;
        private String nameEvent;
        private String description;
        private String location;
        private Date beginDate;
        private Date endDate;
        private int client;
        private String project;
     
        public Events() {
        }
     
        public Events(int user, String nameEvent, String description, String location, Date beginDate, Date endDate, int client, String project) {
            this.user = user;
            this.nameEvent = nameEvent;
            this.description = description;
            this.location = location;
            this.beginDate = beginDate;
            this.endDate = endDate;
            this.client = client;
            this.project = project;
        }
     
        @Id
        @GeneratedValue(strategy = IDENTITY)
        @Column(name = "id_event", unique = true, nullable = false)
        public Integer getIdEvent() {
            return this.idEvent;
        }
     
        public void setIdEvent(Integer idEvent) {
            this.idEvent = idEvent;
        }
     
        @Column(name = "user", nullable = false)
        public int getUser() {
            return this.user;
        }
     
        public void setUser(int user) {
            this.user = user;
        }
     
        @Column(name = "name_event", nullable = false, length = 25)
        public String getNameEvent() {
            return this.nameEvent;
        }
     
        public void setNameEvent(String nameEvent) {
            this.nameEvent = nameEvent;
        }
     
        @Column(name = "description", nullable = false, length = 50)
        public String getDescription() {
            return this.description;
        }
     
        public void setDescription(String description) {
            this.description = description;
        }
     
        @Column(name = "location", nullable = false, length = 25)
        public String getLocation() {
            return this.location;
        }
     
        public void setLocation(String location) {
            this.location = location;
        }
     
        @Temporal(TemporalType.DATE)
        @Column(name = "begin_date", nullable = false, length = 10)
        public Date getBeginDate() {
            return this.beginDate;
        }
     
        public void setBeginDate(Date beginDate) {
            this.beginDate = beginDate;
        }
     
        @Temporal(TemporalType.DATE)
        @Column(name = "end_date", nullable = false, length = 10)
        public Date getEndDate() {
            return this.endDate;
        }
     
        public void setEndDate(Date endDate) {
            this.endDate = endDate;
        }
     
        @Column(name = "client", nullable = false)
        public int getClient() {
            return this.client;
        }
     
        public void setClient(int client) {
            this.client = client;
        }
     
        @Column(name = "project", nullable = false, length = 25)
        public String getProject() {
            return this.project;
        }
     
        public void setProject(String project) {
            this.project = project;
        }
    son fichier de mapping :
    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
    <hibernate-mapping>
        <class catalog="calendar" name="entites.Events" table="events">
            <id name="idEvent" type="java.lang.Integer">
                <column name="id_event"/>
                <generator class="identity"/>
            </id>
     
            <property name="user" type="int">
                <column name="user" not-null="true"/>
            </property>
     
            <property name="nameEvent" type="string">
                <column length="25" name="name_event" not-null="true"/>
            </property>
     
            <property name="description" type="string">
                <column length="50" name="description" not-null="true"/>
            </property>
     
            <property name="location" type="string">
                <column length="25" name="location" not-null="true"/>
            </property>
     
            <property name="beginDate" type="date">
                <column length="10" name="begin_date" not-null="true"/>
            </property>
     
            <property name="endDate" type="date">
                <column length="10" name="end_date" not-null="true"/>
            </property>
     
            <property name="client" type="int">
                <column name="client" not-null="true"/>
            </property>
     
            <property name="project" type="string">
                <column length="25" name="project" not-null="true"/>
            </property>
        </class>
    </hibernate-mapping>
    Et mon bean client :
    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
    @Entity
    @Table(name = "clients", catalog = "calendar")
    public class Clients implements java.io.Serializable {
     
        private Integer idClient;
        private String nameClient;
        private String address;
        private String phone;
        private String contact;
        private String color;
     
        public Clients() {
        }
     
        public Clients(String nameClient, String address, String phone, String contact, String color) {
            this.nameClient = nameClient;
            this.address = address;
            this.phone = phone;
            this.contact = contact;
            this.color = color;
        }
     
        @Id
        @GeneratedValue(strategy = IDENTITY)
        @Column(name = "id_client", unique = true, nullable = false)
        public Integer getIdClient() {
            return this.idClient;
        }
     
        public void setIdClient(Integer idClient) {
            this.idClient = idClient;
        }
     
        @Column(name = "name_client", nullable = false, length = 25)
        public String getNameClient() {
            return this.nameClient;
        }
     
        public void setNameClient(String nameClient) {
            this.nameClient = nameClient;
        }
     
        @Column(name = "address", nullable = false, length = 100)
        public String getAddress() {
            return this.address;
        }
     
        public void setAddress(String address) {
            this.address = address;
        }
     
        @Column(name = "phone", nullable = false, length = 15)
        public String getPhone() {
            return this.phone;
        }
     
        public void setPhone(String phone) {
            this.phone = phone;
        }
     
        @Column(name = "contact", nullable = false, length = 25)
        public String getContact() {
            return this.contact;
        }
     
        public void setContact(String contact) {
            this.contact = contact;
        }
     
        @Column(name = "color", nullable = false, length = 10)
        public String getColor() {
            return this.color;
        }
     
        public void setColor(String color) {
            this.color = color;
        }
    et son fichier de mapping :
    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
    <hibernate-mapping>
        <class catalog="calendar" name="entites.Clients" table="clients">
            <id name="idClient" type="java.lang.Integer">
                <column name="id_client"/>
                <generator class="identity"/>
            </id>
     
            <property name="nameClient" type="string">
                <column length="25" name="name_client" not-null="true"/>
            </property>
     
            <property name="address" type="string">
                <column length="100" name="address" not-null="true"/>
            </property>
     
            <property name="phone" type="string">
                <column length="15" name="phone" not-null="true"/>
            </property>
     
            <property name="contact" type="string">
                <column length="25" name="contact" not-null="true"/>
            </property>
     
            <property name="color" type="string">
                <column length="10" name="color" not-null="true"/>
            </property>
     
        </class>
    </hibernate-mapping>
    J'ai cherché et j'ai trouvé des info sur @OneToOne et @ManyToOne mais je n'arrive pas à l'appliquer...

    Merci de votre aide.

  2. #2
    Membre régulier
    Profil pro
    Inscrit en
    Février 2007
    Messages
    120
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2007
    Messages : 120
    Points : 83
    Points
    83
    Par défaut
    Bon j'ai finalement trouvé,

    Pour ceux à qui ça interresserai :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    <many-to-one name="clientOfEvent" lazy="false"
                         insert="false"
                         update="false"
                         class="entites.Clients"
                         column="client"
                         not-null="true"
                         foreign-key="fk_events_client"/>
    Il faut ajouter ce code dans la fichier de mapping du POJO

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

Discussions similaires

  1. [hibernate][spring] première application
    Par iftolotfi dans le forum Hibernate
    Réponses: 2
    Dernier message: 01/06/2006, 07h03
  2. Réponses: 10
    Dernier message: 31/05/2006, 16h15
  3. [Hibernate - Spring] Spring => Version 2 d'Hibernate?
    Par cicolas dans le forum Hibernate
    Réponses: 2
    Dernier message: 30/05/2006, 16h22
  4. [hibernate][spring]requete select from where IN
    Par whilecoyote dans le forum Hibernate
    Réponses: 1
    Dernier message: 07/04/2006, 09h06
  5. [Hibernate][Spring] Session Hibernate initialisée
    Par mauvais_karma dans le forum Hibernate
    Réponses: 12
    Dernier message: 08/08/2005, 13h07

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