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 :

jointure entre les tables


Sujet :

Hibernate Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Inscrit en
    Février 2010
    Messages
    66
    Détails du profil
    Informations forums :
    Inscription : Février 2010
    Messages : 66
    Par défaut jointure entre les tables
    Bonjour

    J'ai une jointure entre les tables employes et vacation one to many
    Hibernate a généré les deux classes Employes et Vacation
    Je voudrais calculer la durée des congés en une année pour chaque employés ! j'ai essayé d'utiliser les requêtes SQL classiques dans la couche service. Mais je ne sais pas comment faire?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    public List<Double> findDuration() {
    		return (List<Double>) hibernateTemplate
    				.find("select duration from Vacation INNER Join Employes ON Vacation.employes.id=Employes.id where employes.id=?1 ");
    		//DELETE salaire.* FROM Employés INNER JOIN Salaire ON Employés.NumEmployé = Salaire.NumEmployé
    	}
    SVP help me !

  2. #2
    Membre très actif Avatar de yacine.dev
    Inscrit en
    Octobre 2009
    Messages
    177
    Détails du profil
    Informations personnelles :
    Âge : 37

    Informations forums :
    Inscription : Octobre 2009
    Messages : 177
    Par défaut
    Bonjour,pour bien comprendre hibernate voila un référence qui s'appelle "hibernate in action" si vous comprenez l'anglais surement il vous aidera.

    veuillez nous donner les attributs de employé et vacation.

  3. #3
    Membre confirmé
    Inscrit en
    Février 2010
    Messages
    66
    Détails du profil
    Informations forums :
    Inscription : Février 2010
    Messages : 66
    Par défaut
    Citation Envoyé par yacine.dev Voir le message
    Bonjour,pour bien comprendre hibernate voila un référence qui s'appelle "hibernate in action" si vous comprenez l'anglais surement il vous aidera.

    veuillez nous donner les attributs de employé et vacation.
    Merci pour votre réponse ! je vais voir le livre

    Voici mes classes POJO Employes et Vacation

    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
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    package com.proxymit.grh.model;
     
    // default package
    // Generated 10 avr. 2010 00:19:55 by Hibernate Tools 3.2.4.GA
     
     
     
    import java.util.Date;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.FetchType;
    import javax.persistence.Id;
    import javax.persistence.JoinColumn;
    import javax.persistence.ManyToOne;
    import javax.persistence.Table;
    import javax.persistence.Temporal;
    import javax.persistence.TemporalType;
     
    /**
     * Vacation generated by hbm2java
     */
    @Entity
    @Table(name = "vacation", catalog = "proxym")
    public class Vacation implements java.io.Serializable {
     
    	private int idvacation;
    	private Employes employes;
    	private Vacationtype vacationtype;
    	private Date startDate;
    	private Date endDate;
    	private Double duration;
    	private Integer numberOfWorkingDays;
    	private Integer halfDay;
    	private String createdAt;
    	private Boolean state;
    	private String reason;
     
     
     
     
    	public Vacation() {
    	}
     
    	public Vacation(int idvacation, Employes employes, Vacationtype vacationtype) {
    		this.idvacation = idvacation;
    		this.employes = employes;
    		this.vacationtype = vacationtype;
    	}
     
    	public Vacation(int idvacation, Employes employes,
    			Vacationtype vacationtype, Date startDate, Date endDate,
    			Double duration, Integer numberOfWorkingDays, Integer halfDay,
    			String createdAt, Boolean state, String reason) {
    		this.idvacation = idvacation;
    		this.employes = employes;
    		this.vacationtype = vacationtype;
    		this.startDate = startDate;
    		this.endDate = endDate;
    		this.duration = duration;
    		this.numberOfWorkingDays = numberOfWorkingDays;
    		this.halfDay = halfDay;
    		this.createdAt = createdAt;
    		this.state = state;
    		this.reason = reason;
    	}
     
    	@Id
    	@Column(name = "idvacation", unique = true, nullable = false)
    	public int getIdvacation() {
    		return this.idvacation;
    	}
     
    	public void setIdvacation(int idvacation) {
    		this.idvacation = idvacation;
    	}
     
    	@ManyToOne(fetch = FetchType.LAZY)
    	@JoinColumn(name = "employes_ID")
    	public Employes getEmployes() {
    		return this.employes;
    	}
     
    	public void setEmployes(Employes employes) {
    		this.employes = employes;
    	}
     
    	@ManyToOne(fetch = FetchType.LAZY)
    	@JoinColumn(name = "vacationtype_idvacationtype")
    	public Vacationtype getVacationtype() {
    		return this.vacationtype;
    	}
     
    	public void setVacationtype(Vacationtype vacationtype) {
    		this.vacationtype = vacationtype;
    	}
     
    	@Temporal(TemporalType.DATE)
    	@Column(name = "Start_date", length = 0)
    	public Date getStartDate() {
    		return this.startDate;
    	}
     
    	public void setStartDate(Date startDate) {
    		this.startDate = startDate;
    	}
     
    	@Temporal(TemporalType.DATE)
    	@Column(name = "End_date", length = 0)
    	public Date getEndDate() {
    		return this.endDate;
    	}
     
    	public void setEndDate(Date endDate) {
    		this.endDate = endDate;
    	}
     
    	@Column(name = "duration", precision = 22, scale = 0)
    	public Double getDuration() {
    		return this.duration;
    	}
     
    	public void setDuration(Double duration) {
    		this.duration = duration;
    	}
     
    	@Column(name = "number_of_working_days")
    	public Integer getNumberOfWorkingDays() {
    		return this.numberOfWorkingDays;
    	}
     
    	public void setNumberOfWorkingDays(Integer numberOfWorkingDays) {
    		this.numberOfWorkingDays = numberOfWorkingDays;
    	}
     
    	@Column(name = "half_day")
    	public Integer getHalfDay() {
    		return this.halfDay;
    	}
     
    	public void setHalfDay(Integer halfDay) {
    		this.halfDay = halfDay;
    	}
     
    	@Column(name = "created_at", length = 65535)
    	public String getCreatedAt() {
    		return this.createdAt;
    	}
     
    	public void setCreatedAt(String createdAt) {
    		this.createdAt = createdAt;
    	}
     
    	@Column(name = "state")
    	public Boolean getState() {
    		return this.state;
    	}
     
    	public void setState(Boolean state) {
    		this.state = state;
    	}
     
    	@Column(name = "reason", length = 65535)
    	public String getReason() {
    		return this.reason;
    	}
     
    	public void setReason(String reason) {
    		this.reason = reason;
    	}
     
     
     
    }
    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
    package com.proxymit.grh.model;
     
    // default package
    // Generated 10 avr. 2010 00:19:55 by Hibernate Tools 3.2.4.GA
     
    import java.util.HashSet;
    import java.util.Set;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.FetchType;
    import javax.persistence.GeneratedValue;
    import static javax.persistence.GenerationType.IDENTITY;
    import javax.persistence.Id;
    import javax.persistence.OneToMany;
    import javax.persistence.Table;
     
    /**
     * Employes generated by hbm2java
     */
    @Entity
    @Table(name = "employes", catalog = "proxym")
    public class Employes implements java.io.Serializable {
     
    	private Integer id;
    	private String nom;
    	private String prenom;
    	private String email;
    	private String pays;
    	private Boolean enabled;
    	private String login;
    	private String password;
    	private Set<Vacation> vacations = new HashSet<Vacation>(0);
     
    	public Employes() {
    	}
     
    	public Employes(String nom, String prenom, String email, String pays,
    			Boolean enabled, String login, String password,
    			Set<Vacation> vacations) {
    		this.nom = nom;
    		this.prenom = prenom;
    		this.email = email;
    		this.pays = pays;
    		this.enabled = enabled;
    		this.login = login;
    		this.password = password;
    		this.vacations = vacations;
    	}
     
    	@Id
    	@GeneratedValue(strategy = IDENTITY)
    	@Column(name = "ID", unique = true, nullable = false)
    	public Integer getId() {
    		return this.id;
    	}
     
    	public void setId(Integer id) {
    		this.id = id;
    	}
     
    	@Column(name = "nom", length = 45)
    	public String getNom() {
    		return this.nom;
    	}
     
    	public void setNom(String nom) {
    		this.nom = nom;
    	}
     
    	@Column(name = "prenom", length = 45)
    	public String getPrenom() {
    		return this.prenom;
    	}
     
    	public void setPrenom(String prenom) {
    		this.prenom = prenom;
    	}
     
    	@Column(name = "email", length = 45)
    	public String getEmail() {
    		return this.email;
    	}
     
    	public void setEmail(String email) {
    		this.email = email;
    	}
     
    	@Column(name = "pays", length = 50)
    	public String getPays() {
    		return this.pays;
    	}
     
    	public void setPays(String pays) {
    		this.pays = pays;
    	}
     
    	@Column(name = "enabled")
    	public Boolean getEnabled() {
    		return this.enabled;
    	}
     
    	public void setEnabled(Boolean enabled) {
    		this.enabled = enabled;
    	}
     
    	@Column(name = "login", length = 50)
    	public String getLogin() {
    		return this.login;
    	}
     
    	public void setLogin(String login) {
    		this.login = login;
    	}
     
    	@Column(name = "password", length = 50)
    	public String getPassword() {
    		return this.password;
    	}
     
    	public void setPassword(String password) {
    		this.password = password;
    	}
     
    	@OneToMany(fetch = FetchType.LAZY, mappedBy = "employes")
    	public Set<Vacation> getVacations() {
    		return this.vacations;
    	}
     
    	public void setVacations(Set<Vacation> vacations) {
    		this.vacations = vacations;
    	}
     
    }

    voici la réquète SQL que je vais transformer en HQL utilisant hibernate çàd dans la couche service.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    SELECT sum( datediff( vtn.End_date, vtn.Start_date ) )
    FROM vacation vtn
    WHERE vtn.employes_ID =1
    AND vtn.Start_date > "01-01-2010"
    AND vtn.End_date < "31-12-2010"
    J'ai fait le binding de Emplyes avec Vacation dans mon controlleur (j'utilise Spring MVC)


    merci pour votre aide !

  4. #4
    Membre très actif Avatar de yacine.dev
    Inscrit en
    Octobre 2009
    Messages
    177
    Détails du profil
    Informations personnelles :
    Âge : 37

    Informations forums :
    Inscription : Octobre 2009
    Messages : 177
    Par défaut
    vous devez poster dans le forum d'hibernate pour trouver une réponse

  5. #5
    Membre confirmé
    Inscrit en
    Février 2010
    Messages
    66
    Détails du profil
    Informations forums :
    Inscription : Février 2010
    Messages : 66
    Par défaut
    Citation Envoyé par yacine.dev Voir le message
    vous devez poster dans le forum d'hibernate pour trouver une réponse
    Désolée
    J'ai cherché dans les forums mais je vois pas de forum pour Hibernate .
    Ou je peux trouver ça ??

Discussions similaires

  1. jointure entre les tables php
    Par programmatrice dans le forum Langage
    Réponses: 9
    Dernier message: 07/04/2012, 14h48
  2. Jointure entre les tables
    Par l'coy dans le forum Langage SQL
    Réponses: 2
    Dernier message: 06/04/2011, 09h36
  3. ERP Movex - jointure entre les tables CINACC et FGLEDG
    Par cami_lori dans le forum Autres ERP
    Réponses: 0
    Dernier message: 22/06/2009, 16h14
  4. Jointure entre les tables
    Par zalalus dans le forum Débuter
    Réponses: 3
    Dernier message: 15/04/2009, 09h03
  5. Jointure entre les tables
    Par zaac01 dans le forum Outils
    Réponses: 1
    Dernier message: 03/12/2007, 15h26

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