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

JPA Java Discussion :

Problème identifiant hybride [Débutant(e)]


Sujet :

JPA Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Homme Profil pro
    graphisme & impression
    Inscrit en
    Mars 2011
    Messages
    118
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : graphisme & impression

    Informations forums :
    Inscription : Mars 2011
    Messages : 118
    Par défaut Problème identifiant hybride
    Bonjour à tous,

    Je suis débutant en informatique et je n'arrive pas à trouver une solution depuis 2 jours déjà

    Problème:
    J'ai une Table consultation (ID: Date & PatientNo) et une table Patient(No)
    Je n'arrive pas à creer une clé primaire "composite pour la table Consultation?

    Est ce que quelqu'un pourrait-il me donner un exemple?
    Merci beaucoup pour votre aide!
    Bonne journée

    P.-S. Patient hérite de Personne

    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
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
     
    package entites;
     
    import java.io.Serializable;
     
    import java.util.Date;
    import java.util.HashSet;
    import java.util.Set;
     
    import javax.persistence.CascadeType;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.OneToMany;
    import javax.persistence.Table;
    import javax.persistence.Temporal;
    import javax.persistence.TemporalType;
     
     
     
     
     
    @SuppressWarnings("serial")
    @Entity
    @Table(name="patient")
    public class Patient extends Personne implements Serializable{
     
     
    	@Column(name="caisseMaladie", length = 30, nullable = false)
    	private String caisseMaladie;
     
    	@Column(name="datePremVisite", nullable=true)
    	@Temporal(TemporalType.DATE)
    	private Date datePremVisite;
     
    	@OneToMany(mappedBy="patientAppartientConsultation", cascade = { CascadeType.ALL })
    	private Set<Consultation> listConsultation;
     
    	public Patient(String pPrenom, String pNom, String pProfession, Date pDateNaissance, String pNumeroTel, String pMail, 
    			String pCaisseMaladie, Date pDatePremVisite){
    		super(pPrenom, pNom, pProfession, pDateNaissance, pNumeroTel, pMail);
    		setCaisseMaladie(pCaisseMaladie);
    		setDatePremVisite(pDatePremVisite);
    		this.listConsultation = new HashSet<Consultation>();
    	}
     
    	public void addConsultation(Consultation pConsultation){
    		this.listConsultation.add(pConsultation);
    		pConsultation.setPatientAppartientConsultation(this);
    	}
     
    	// getters
    	public String getCaisseMaladie(){
    		return caisseMaladie;
    	}
     
    	public Date getDatePremVisite(){
    		return datePremVisite;
    	}
     
    	// setters
    	public void setCaisseMaladie(String pCaisseMaladie){
    		this.caisseMaladie = pCaisseMaladie;
    	}
     
    	public void setDatePremVisite(Date pDatePremVisite){		
    		this.datePremVisite = pDatePremVisite;
    	}
     
    }
     
     
     
    package entites;
     
    import java.io.Serializable;
    import java.util.Date;
     
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.FetchType;
    import javax.persistence.Id;
    import javax.persistence.IdClass;
    import javax.persistence.JoinColumn;
    import javax.persistence.JoinColumns;
    import javax.persistence.ManyToOne;
    import javax.persistence.Table;
    import javax.persistence.Temporal;
    import javax.persistence.TemporalType;
     
     
    @SuppressWarnings("serial")
    @Entity
    @Table(name="consultation")
    public class Consultation implements Serializable{
     
     
    	@Id
    	@Column(name="date", nullable = false)
    	@Temporal(TemporalType.TIMESTAMP)
    	private Date date;
     
            @Id
    	@ManyToOne(fetch=FetchType.LAZY)
    	@JoinColumn(name = "patient_id", nullable = false)
    	private Patient patientAppartientConsultation;
     
    	@Column(name="remarque", nullable = true)
    	private String remarque;
     
    	public Consultation(Date pDate, String pRemarque){
    		this.date = pDate;
    		this.remarque = pRemarque;
    	}
     
     
    	public Date getDate() {
    		return date;
    	}
     
    	public void setDate(Date date) {
    		this.date = date;
    	}
     
    	public String getRemarque() {
    		return remarque;
    	}
     
    	public void setRemarque(String remarque) {
    		this.remarque = remarque;
    	}
     
    	public Patient getPatientAppartientConsultation() {
    		return patientAppartientConsultation;
    	}
     
    	public void setPatientAppartientConsultation(
    			Patient patientAppartientConsultation) {
    		this.patientAppartientConsultation = patientAppartientConsultation;
    	}
     
     
    }
     
     
    package entites;
     
    import java.io.Serializable;
     
    import java.util.Date;
     
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.Inheritance;
    import javax.persistence.InheritanceType;
    import javax.persistence.Table;
    import javax.persistence.Temporal;
    import javax.persistence.TemporalType;
     
    @SuppressWarnings("serial")
    @Entity
    @Inheritance(strategy=InheritanceType.JOINED)
    @Table(name="personne")
    public abstract class Personne implements Serializable{
     
    	@Id
    	@Column(name = "id", nullable = false)
    	@GeneratedValue(strategy = GenerationType.AUTO)
    	private Integer id;
     
    	@Column(name = "prenom", length = 30, nullable = false, unique = false)
    	private String prenom;
     
    	@Column(name = "nom", length = 30, nullable = false, unique = false)
    	private String nom;
     
    	@Column(name = "profession", length = 30, nullable = true)
    	private String profession;
     
    	@Column(name = "DATENAISSANCE", nullable = false)
    	@Temporal(TemporalType.DATE)
    	private Date dateNaissance;
     
    	@Column(name = "numeroTel", nullable = true)
    	private String numeroTel;
     
    	@Column(name = "mail", length = 30, nullable = true)
    	private String mail;
     
    	public Personne(String pPrenom, String pNom, String pProfession, Date pDateNaissance, String pNumeroTel, String pMail){
    		setPrenom(pPrenom);
    		setNom(pNom);
    		setProfession(pProfession);
    		setDateNaissance(pDateNaissance);
    		setNumeroTel(pNumeroTel);
    		setMail(pMail);
    	}
     
    	public Integer getId() {
    		return id;
    	}
     
    	public void setId(Integer id) {
    		this.id = id;
    	}
     
    	public String getPrenom() {
    		return prenom;
    	}
     
    	public void setPrenom(String prenom) {
    		this.prenom = prenom;
    	}
     
    	public String getNom() {
    		return nom;
    	}
     
    	public void setNom(String nom) {
    		this.nom = nom;
    	}
     
    	public String getProfession() {
    		return profession;
    	}
     
    	public void setProfession(String profession) {
    		this.profession = profession;
    	}
     
    	public Date getDateNaissance() {
    		return dateNaissance;
    	}
     
    	public void setDateNaissance(Date dateNaissance) {
    		this.dateNaissance = dateNaissance;
    	}
     
    	public String getNumeroTel() {
    		return numeroTel;
    	}
     
    	public void setNumeroTel(String numeroTel) {
    		this.numeroTel = numeroTel;
    	}
     
    	public String getMail() {
    		return mail;
    	}
     
    	public void setMail(String mail) {
    		this.mail = mail;
    	}
     
     
     
     
    }

  2. #2
    Membre Expert
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juin 2007
    Messages
    2 938
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Juin 2007
    Messages : 2 938
    Par défaut
    Très facile, un exemple ici

  3. #3
    Membre confirmé
    Homme Profil pro
    graphisme & impression
    Inscrit en
    Mars 2011
    Messages
    118
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : graphisme & impression

    Informations forums :
    Inscription : Mars 2011
    Messages : 118
    Par défaut merci
    Citation Envoyé par DevServlet Voir le message
    Très facile, un exemple ici
    Hello,

    Merci beaucoup pour ton poste, c'est très sympa.
    Alors j'ai déjà consulté cette page et malheureusement sans succès!

    Je n'arrive pas à comprendre ce qui ne marche pas dans mon code?
    Je suis débutant et je ne comprends pas l'erreur suivante:

    BD:
    [hibernatetool] Executing Hibernate Tool with a JPA Configuration
    [hibernatetool] 1. task: hbm2ddl (Generates database schema)
    [hibernatetool] An exception occurred while running exporter #2:hbm2ddl (Generates database schema)
    [hibernatetool] To get the full stack trace run ant with -verbose
    [hibernatetool] Problems in creating a configuration for JPA. Have you remembered to add hibernate EntityManager jars to the classpath ?
    [hibernatetool] java.lang.reflect.InvocationTargetException
    [hibernatetool] javax.persistence.PersistenceException: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: entites.Consultation.patientAppartientConsultation in entites.Patient.listConsultation
    [hibernatetool] org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: entites.Consultation.patientAppartientConsultation in entites.Patient.listConsultation


    Merci beaucoup!

    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
     
    package entites;
     
    import java.io.Serializable;
    import java.util.Date;
     
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.FetchType;
    import javax.persistence.Id;
    import javax.persistence.IdClass;
    import javax.persistence.JoinColumn;
    import javax.persistence.JoinColumns;
    import javax.persistence.ManyToOne;
    import javax.persistence.Table;
    import javax.persistence.Temporal;
    import javax.persistence.TemporalType;
     
     
    @SuppressWarnings("serial")
    @Entity
    @Table(name="consultation")
    @IdClass(ConsultationId.class)
    public class Consultation implements Serializable{
     
     
    	@Id
    	@Column(name="date", nullable = false)
    	@Temporal(TemporalType.TIMESTAMP)
    	private Date date;
     
    	@Id
    	@ManyToOne(fetch=FetchType.LAZY)
    	@JoinColumn(name = "patient_id", nullable = false)
    	private Patient patientAppartientConsultation;
     
    	@Column(name="remarque", nullable = true)
    	private String remarque;
     
    	public Consultation(Date pDate, String pRemarque){
    		this.date = pDate;
    		this.remarque = pRemarque;
    	}
     
     
    	public Date getDate() {
    		return date;
    	}
     
    	public void setDate(Date date) {
    		this.date = date;
    	}
     
    	public String getRemarque() {
    		return remarque;
    	}
     
    	public void setRemarque(String remarque) {
    		this.remarque = remarque;
    	}
     
    	public Patient getPatientAppartientConsultation() {
    		return patientAppartientConsultation;
    	}
     
    	public void setPatientAppartientConsultation(
    			Patient patientAppartientConsultation) {
    		this.patientAppartientConsultation = patientAppartientConsultation;
    	}
     
     
    }
     
     
    package entites;
     
    import java.util.Date;
     
    class ConsultationId {
     
    	private Date date;
    	private Patient patientAppartientConsultation;
     
    }
     
     
     
    package entites;
     
    import java.io.Serializable;
     
    import java.util.Date;
    import java.util.HashSet;
    import java.util.Set;
     
    import javax.persistence.CascadeType;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.OneToMany;
    import javax.persistence.Table;
    import javax.persistence.Temporal;
    import javax.persistence.TemporalType;
     
     
     
     
     
    @SuppressWarnings("serial")
    @Entity
    @Table(name="patient")
    public class Patient extends Personne implements Serializable{
     
     
    	@Column(name="caisseMaladie", length = 30, nullable = false)
    	private String caisseMaladie;
     
    	@Column(name="datePremVisite", nullable=true)
    	@Temporal(TemporalType.DATE)
    	private Date datePremVisite;
     
    	@OneToMany(mappedBy="patientAppartientConsultation", cascade = { CascadeType.ALL })
    	private Set<Consultation> listConsultation;
     
    	public Patient(String pPrenom, String pNom, String pProfession, Date pDateNaissance, String pNumeroTel, String pMail, 
    			String pCaisseMaladie, Date pDatePremVisite){
    		super(pPrenom, pNom, pProfession, pDateNaissance, pNumeroTel, pMail);
    		setCaisseMaladie(pCaisseMaladie);
    		setDatePremVisite(pDatePremVisite);
    		this.listConsultation = new HashSet<Consultation>();
    	}
     
    	public void addConsultation(Consultation pConsultation){
    		this.listConsultation.add(pConsultation);
    		pConsultation.setPatientAppartientConsultation(this);
    	}
     
    	// getters
    	public String getCaisseMaladie(){
    		return caisseMaladie;
    	}
     
    	public Date getDatePremVisite(){
    		return datePremVisite;
    	}
     
    	// setters
    	public void setCaisseMaladie(String pCaisseMaladie){
    		this.caisseMaladie = pCaisseMaladie;
    	}
     
    	public void setDatePremVisite(Date pDatePremVisite){		
    		this.datePremVisite = pDatePremVisite;
    	}
     
    }

  4. #4
    Membre confirmé
    Homme Profil pro
    Développeur Java
    Inscrit en
    Octobre 2009
    Messages
    169
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Octobre 2009
    Messages : 169
    Par défaut
    ajoute :

    sur la class ConsultationId

    et la class Consultation devient :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    @EmbeddedId
    private ConsultationId id ;
     
    @Column(name="date", nullable = false, insertable=false, updatable=false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date date;
     
    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name = "patient_id", nullable = false, insertable=false, updatable=false)
    private Patient patientAppartientConsultation;
    çà devrait solutionner ton problème je pense.

    HadanMarv

  5. #5
    Membre confirmé
    Homme Profil pro
    graphisme & impression
    Inscrit en
    Mars 2011
    Messages
    118
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : graphisme & impression

    Informations forums :
    Inscription : Mars 2011
    Messages : 118
    Par défaut merci!
    Hello,

    J'ai ajouté ta proposition… Malheureusement l'erreur reste.
    J'ai relu un peu la doc et cela semble effectivement mieux mais je ne comprends toujours pas d'où vient l'erreur…

    J'arrive à creer une class avec un ID hybride simple, mais lorsqu'il s'agit comme ici d'une relation comme ID ça se complique

    erreur:

    Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): entites.Consultation
    at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:647)
    at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:218)
    at tests.test.main(Unknown Source)
    Caused by: org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): entites.Consultation
    at org.hibernate.id.Assigned.generate(Assigned.java:33)

    Une autre idée?
    Merci infiniment!

    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
     
     
    package entites;
     
    import java.io.Serializable;
    import java.util.Date;
     
    import javax.persistence.Column;
    import javax.persistence.EmbeddedId;
    import javax.persistence.Entity;
    import javax.persistence.FetchType;
    import javax.persistence.Id;
    import javax.persistence.IdClass;
    import javax.persistence.JoinColumn;
    import javax.persistence.JoinColumns;
    import javax.persistence.ManyToOne;
    import javax.persistence.Table;
    import javax.persistence.Temporal;
    import javax.persistence.TemporalType;
     
     
    @SuppressWarnings("serial")
    @Entity
    @Table(name="consultation")
    public class Consultation implements Serializable{
     
     
    	@EmbeddedId
    	private ConsultationId id;
     
    	@Column(name="date", nullable = false, insertable=false, updatable=false)
    	@Temporal(TemporalType.TIMESTAMP)
    	private Date date;
     
    	@ManyToOne(fetch=FetchType.LAZY)
    	@JoinColumn(name = "patient_id", nullable = false, insertable=false, updatable=false)
    	private Patient patientAppartientConsultation;
     
    	@Column(name="remarque", nullable = true)
    	private String remarque;
     
    	public Consultation(Date pDate, String pRemarque){
    		this.date = pDate;
    		this.remarque = pRemarque;
    	}
     
     
    	public Date getDate() {
    		return date;
    	}
     
    	public void setDate(Date date) {
    		this.date = date;
    	}
     
    	public String getRemarque() {
    		return remarque;
    	}
     
    	public void setRemarque(String remarque) {
    		this.remarque = remarque;
    	}
     
    	public Patient getPatientAppartientConsultation() {
    		return patientAppartientConsultation;
    	}
     
    	public void setPatientAppartientConsultation(
    			Patient patientAppartientConsultation) {
    		this.patientAppartientConsultation = patientAppartientConsultation;
    	}
     
     
    }
     
     
     
    package entites;
     
    import java.io.Serializable;
    import java.util.Date;
     
    import javax.persistence.Embeddable;
     
    @Embeddable
    class ConsultationId implements Serializable{
     
    	private Date date;
    	private Patient patientAppartientConsultation;
     
    }
     
     
    package entites;
     
    import java.io.Serializable;
     
    import java.util.Date;
    import java.util.HashSet;
    import java.util.Set;
     
    import javax.persistence.CascadeType;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.IdClass;
    import javax.persistence.OneToMany;
    import javax.persistence.Table;
    import javax.persistence.Temporal;
    import javax.persistence.TemporalType;
     
     
     
     
     
    @SuppressWarnings("serial")
    @Entity
    @Table(name="patient")
    public class Patient extends Personne implements Serializable{
     
     
    	@Column(name="caisseMaladie", length = 30, nullable = false)
    	private String caisseMaladie;
     
    	@Column(name="datePremVisite", nullable=true)
    	@Temporal(TemporalType.DATE)
    	private Date datePremVisite;
     
    	@OneToMany(mappedBy="patientAppartientConsultation", cascade = { CascadeType.ALL })
    	private Set<Consultation> listConsultation;
     
    	public Patient(String pPrenom, String pNom, String pProfession, Date pDateNaissance, String pNumeroTel, String pMail, 
    			String pCaisseMaladie, Date pDatePremVisite){
    		super(pPrenom, pNom, pProfession, pDateNaissance, pNumeroTel, pMail);
    		setCaisseMaladie(pCaisseMaladie);
    		setDatePremVisite(pDatePremVisite);
    		this.listConsultation = new HashSet<Consultation>();
    	}
     
    	public void addConsultation(Consultation pConsultation){
    		this.listConsultation.add(pConsultation);
    		pConsultation.setPatientAppartientConsultation(this);
    	}
     
    	// getters
    	public String getCaisseMaladie(){
    		return caisseMaladie;
    	}
     
    	public Date getDatePremVisite(){
    		return datePremVisite;
    	}
     
    	// setters
    	public void setCaisseMaladie(String pCaisseMaladie){
    		this.caisseMaladie = pCaisseMaladie;
    	}
     
    	public void setDatePremVisite(Date pDatePremVisite){		
    		this.datePremVisite = pDatePremVisite;
    	}
     
    }

  6. #6
    Membre confirmé
    Homme Profil pro
    Développeur Java
    Inscrit en
    Octobre 2009
    Messages
    169
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Octobre 2009
    Messages : 169
    Par défaut
    La nouvelle expection que tu reçois est logique puisque les valeurs de la clé composite doivent être assigné.
    Ainsi lors de l'assignation des variales il faut assigner celle de l'id (ConsultationId) et non pas celle de consultation.
    Tu dois surement faire :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    Consultation uneConsultation = new Consultation() ;
    uneConsultation.setDate(taDate) ;
    uneConsultation.setPatientAppartientConsultation(tonPatient) ;
    alors que tu devrais faire :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    Consultation uneConsultation = new Consultation() ;
    uneConsultation.getId().setDate(taDate) ;
    uneConsultation.getId().setPatientAppartientConsultation(tonPatient) ;
    ou bien modifier les setters par défaut sur la class Consultation
    Pas sûre d'être très clair pour le coup.

    HadanMarv

  7. #7
    Membre confirmé
    Homme Profil pro
    graphisme & impression
    Inscrit en
    Mars 2011
    Messages
    118
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : graphisme & impression

    Informations forums :
    Inscription : Mars 2011
    Messages : 118
    Par défaut merci!!!
    Hello,

    Je suis encore dessus ce problème (l'important c'est d'y croire)!
    Merci beaucoup à tous, j'ai appris pleins de choses et j'ai bien avancé grâce à vous.

    J'avais effectivement commencé à chercher dans cette direction.
    Je fais la même chose que ta proposition dans le constructeur de la class Consultation et dans la méthode Patient.addConsultation…


    Je reçois l'erreur suivante:
    Exception in thread "main" java.lang.NullPointerException
    at tests.test.main(Unknown Source)

    Si quelqu'un a une idée


    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
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
     
    package tests;
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
     
    import javax.persistence.EntityManager;
    import javax.persistence.EntityManagerFactory;
    import javax.persistence.Persistence;
     
    import servicesunitaires.IServicesUnitaires;
    import servicesunitaires.ServicesUnitairesPatient;
    import toolbox.Message;
     
    import entites.Consultation;
    import entites.NumRCC;
    import entites.Patient;
    import entites.Specialisation;
    import entites.Therapeute;
     
    public class test {
     
        public static void main(String[] args){
     
        	EntityManagerFactory emf = Persistence.createEntityManagerFactory("jpa");
        	EntityManager em = emf.createEntityManager();
     
        	try{
        		em.getTransaction().begin();
        		Patient stephaniePatient = new Patient("monNom", "nom", "graphiste", new SimpleDateFormat("dd-MM-yy").parse("31-01-2000"), "0264133060", "mail@gmail.com", "assurranceMaladie", new SimpleDateFormat("dd/MM/yy").parse("31/01/2000"));
     
            	Consultation consultation1 = new Consultation(new SimpleDateFormat("dd-MM-yy K:m").parse("01-03-1985 13:20"), "j'ai mal au ventre");
            	stephaniePatient.addConsultation(consultation1);
     
            	em.persist(stephaniePatient);
     
            	em.getTransaction().commit();
        	}
        	catch (ParseException e) {
    			e.printStackTrace();
    		}
        	finally{
        		em.close();
        		emf.close();
        	}
        	System.out.println(Message.getStatut());
        }
    }
     
    package entites;
     
    import java.io.Serializable;
     
    import java.util.Date;
    import java.util.HashSet;
    import java.util.Set;
     
    import javax.persistence.CascadeType;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.IdClass;
    import javax.persistence.OneToMany;
    import javax.persistence.Table;
    import javax.persistence.Temporal;
    import javax.persistence.TemporalType;
     
     
     
     
     
    @SuppressWarnings("serial")
    @Entity
    @Table(name="patient")
    public class Patient extends Personne implements Serializable{
     
     
    	@Column(name="caisseMaladie", length = 30, nullable = false)
    	private String caisseMaladie;
     
    	@Column(name="datePremVisite", nullable=true)
    	@Temporal(TemporalType.DATE)
    	private Date datePremVisite;
     
    	@OneToMany(mappedBy="patientAppartientConsultation", cascade = { CascadeType.ALL })
    	private Set<Consultation> listConsultation;
     
    	public Patient(String pPrenom, String pNom, String pProfession, Date pDateNaissance, String pNumeroTel, String pMail, 
    			String pCaisseMaladie, Date pDatePremVisite){
    		super(pPrenom, pNom, pProfession, pDateNaissance, pNumeroTel, pMail);
    		setCaisseMaladie(pCaisseMaladie);
    		setDatePremVisite(pDatePremVisite);
    		this.listConsultation = new HashSet<Consultation>();
    	}
     
    	public void addConsultation(Consultation pConsultation){
    		pConsultation.setPatientAppartientConsultation(this);
    		this.listConsultation.add(pConsultation);
    	}
     
    	// getters
    	public String getCaisseMaladie(){
    		return caisseMaladie;
    	}
     
    	public Date getDatePremVisite(){
    		return datePremVisite;
    	}
     
    	// setters
    	public void setCaisseMaladie(String pCaisseMaladie){
    		this.caisseMaladie = pCaisseMaladie;
    	}
     
    	public void setDatePremVisite(Date pDatePremVisite){		
    		this.datePremVisite = pDatePremVisite;
    	}
     
    }
     
     
    package entites;
     
    import java.io.Serializable;
    import java.util.Date;
     
    import javax.persistence.Column;
    import javax.persistence.EmbeddedId;
    import javax.persistence.Entity;
    import javax.persistence.FetchType;
    import javax.persistence.Id;
    import javax.persistence.IdClass;
    import javax.persistence.JoinColumn;
    import javax.persistence.JoinColumns;
    import javax.persistence.ManyToOne;
    import javax.persistence.Table;
    import javax.persistence.Temporal;
    import javax.persistence.TemporalType;
     
     
    @SuppressWarnings("serial")
    @Entity
    @Table(name="consultation")
    public class Consultation implements Serializable{
     
     
    	@EmbeddedId
    	private ConsultationId id;
     
    	@Column(name="date", nullable = false, insertable=false, updatable=false)
    	@Temporal(TemporalType.TIMESTAMP)
    	private Date date;
     
    	@ManyToOne(fetch=FetchType.LAZY)
    	@JoinColumn(name = "patient_id", nullable = false, insertable=false, updatable=false)
    	private Patient patientAppartientConsultation;
     
    	@Column(name="remarque", nullable = true)
    	private String remarque;
     
    	public Consultation(Date pDate, String pRemarque){
    		this.date = pDate;
    		this.remarque = pRemarque;
    		this.id.setPatientAppartientConsultation(this.patientAppartientConsultation);
    		this.id.setDate(pDate);
    	}
     
    	public ConsultationId getId() {
    		return id;
    	}
     
    	public void setId(ConsultationId id) {
    		this.id = id;
    	}
     
    	public Date getDate() {
    		return date;
    	}
     
    	public void setDate(Date date) {
    		this.date = date;
    	}
     
    	public Patient getPatientAppartientConsultation() {
    		return patientAppartientConsultation;
    	}
     
    	public void setPatientAppartientConsultation(
    			Patient patientAppartientConsultation) {
    		this.patientAppartientConsultation = patientAppartientConsultation;
    	}
     
    	public String getRemarque() {
    		return remarque;
    	}
     
    	public void setRemarque(String remarque) {
    		this.remarque = remarque;
    	}
     
     
     
     
     
    }
     
     
    package entites;
     
    import java.io.Serializable;
    import java.util.Date;
     
    import javax.persistence.Embeddable;
     
    @Embeddable
    public class ConsultationId implements Serializable{
     
    	private Date date;
     
    	private Patient patientAppartientConsultation;
     
    	public Date getDate() {
    		return date;
    	}
     
    	public void setDate(Date date) {
    		this.date = date;
    	}
     
    	public Patient getPatientAppartientConsultation() {
    		return patientAppartientConsultation;
    	}
     
    	public void setPatientAppartientConsultation(
    			Patient patientAppartientConsultation) {
    		this.patientAppartientConsultation = patientAppartientConsultation;
    	}
     
     
     
     
    }

  8. #8
    Membre confirmé
    Homme Profil pro
    graphisme & impression
    Inscrit en
    Mars 2011
    Messages
    118
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : graphisme & impression

    Informations forums :
    Inscription : Mars 2011
    Messages : 118
    Par défaut problème résolu
    Bonjour,
    Merci à tous mon problème de code est résolu…

    Petit Bonus, j'ai juste un truc bizarre dans ma table Consultation…
    Le champs «patientappartientconsultation» contient un truc bizarre
    cf. Capture d'écran en fichier joint

    En fait je comprends pas l'utilité de ce champs dans ma table ?

    Merci encore pour votre aide!
    Images attachées Images attachées  

  9. #9
    Membre confirmé
    Homme Profil pro
    graphisme & impression
    Inscrit en
    Mars 2011
    Messages
    118
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : graphisme & impression

    Informations forums :
    Inscription : Mars 2011
    Messages : 118
    Par défaut clé primaire et clé secondaire dupliquées!
    Bonjour à tous,

    En fait je crois que je viens de comprendre ce champs! Il s'agit de champs Patient séréalizé … En gros, j'ai dans ma table Consultation (PK Date, PK patient, FK patient)
    Et le but serait d'avoir La clé patient_id en tant que clé Primaire et secondaire

    J'ai essayé d'ajouter insertable=false, updatable=false dans ma relation @ManyToOne dans consultation pour que jpa comprenne que cette relation est aussi la clé primaire et secondaire … (d'après ce que j'ai compris)

    J'ai une erreur:

    08:51:41,586 ERROR JDBCExceptionReporter:72 - L'élément du batch 0 insert into consultation (remarque, date, patientAppartientConsultation) values (j'ai mal au ventre, 1985-03-01 13:20:00.000000 +01:00:00, <stream of 1231 bytes>) a été annulé. Appeler getNextException pour en connaître la cause.
    08:51:41,589 ERROR JDBCExceptionReporter:72 - ERROR: null value in column "patient_id" violates not-null constraint
    08:51:41,590 ERROR AbstractFlushingEventListener:301 - Could not synchronize database state with session


    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
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
     
     
    package entites;
     
    import java.io.Serializable;
    import java.util.Date;
     
    import javax.persistence.Column;
    import javax.persistence.EmbeddedId;
    import javax.persistence.Entity;
    import javax.persistence.FetchType;
    import javax.persistence.Id;
    import javax.persistence.IdClass;
    import javax.persistence.JoinColumn;
    import javax.persistence.JoinColumns;
    import javax.persistence.ManyToOne;
    import javax.persistence.PrimaryKeyJoinColumn;
    import javax.persistence.Table;
    import javax.persistence.Temporal;
    import javax.persistence.TemporalType;
     
     
    @SuppressWarnings("serial")
    @Entity
    @Table(name="consultation")
    public class Consultation implements Serializable{
     
     
    	@EmbeddedId
    	private ConsultationId id;
     
    	@Column(name="date", nullable = false, insertable=false, updatable=false)
    	@Temporal(TemporalType.TIMESTAMP)
    	private Date date;
     
    	@ManyToOne(fetch=FetchType.LAZY)
    	@JoinColumn(name = "patient_id", nullable = false, insertable=false, updatable=false)
    	private Patient patientAppartientConsultation;
     
    	@Column(name="remarque", nullable = true)
    	private String remarque;
     
    	public Consultation(Date pDate, String pRemarque){
    		this.id = new ConsultationId();
    		this.remarque = pRemarque;
    		setDate(pDate);
    	}
     
    	public ConsultationId getId() {
    		return id;
    	}
     
    	public void setId(ConsultationId id) {
    		this.id = id;
    	}
     
    	public Date getDate() {
    		return date;
    	}
     
    	public void setDate(Date date) {
    		this.date = date;
    		this.id.setDate(date);
    	}
     
    	public Patient getPatientAppartientConsultation() {
    		return patientAppartientConsultation;
    	}
     
    	public void setPatientAppartientConsultation(Patient patientAppartientConsultation) {
    		this.patientAppartientConsultation = patientAppartientConsultation;
    		this.id.setPatientAppartientConsultation(patientAppartientConsultation);
    	}
     
    	public String getRemarque() {
    		return remarque;
    	}
     
    	public void setRemarque(String remarque) {
    		this.remarque = remarque;
    	}
     
     
     
     
     
    }
     
    package entites;
     
    import java.io.Serializable;
    import java.util.Date;
     
    import javax.persistence.Column;
    import javax.persistence.Embeddable;
     
    @Embeddable
    public class ConsultationId implements Serializable{
     
    	private Date date;
     
    	private Patient  patientAppartientConsultation;
     
    	public Patient getPatientAppartientConsultation() {
    		return patientAppartientConsultation;
    	}
     
    	public void setPatientAppartientConsultation(Patient patientAppartientConsultation) {
    		this.patientAppartientConsultation = patientAppartientConsultation;
    	}
     
    	public Date getDate() {
    		return date;
    	}
     
    	public void setDate(Date date) {
    		this.date = date;
    	}
     
     
     
     
    }
     
    package entites;
     
    import java.io.Serializable;
     
    import java.util.Date;
    import java.util.HashSet;
    import java.util.Set;
     
    import javax.persistence.CascadeType;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.IdClass;
    import javax.persistence.OneToMany;
    import javax.persistence.Table;
    import javax.persistence.Temporal;
    import javax.persistence.TemporalType;
     
     
     
     
     
    @SuppressWarnings("serial")
    @Entity
    @Table(name="patient")
    public class Patient extends Personne implements Serializable{
     
     
    	@Column(name="caisseMaladie", length = 30, nullable = false)
    	private String caisseMaladie;
     
    	@Column(name="datePremVisite", nullable=true)
    	@Temporal(TemporalType.DATE)
    	private Date datePremVisite;
     
    	@OneToMany(mappedBy="patientAppartientConsultation", cascade = { CascadeType.ALL })
    	private Set<Consultation> listConsultation;
     
    	public Patient(String pPrenom, String pNom, String pProfession, Date pDateNaissance, String pNumeroTel, String pMail, 
    			String pCaisseMaladie, Date pDatePremVisite){
    		super(pPrenom, pNom, pProfession, pDateNaissance, pNumeroTel, pMail);
    		setCaisseMaladie(pCaisseMaladie);
    		setDatePremVisite(pDatePremVisite);
    		this.listConsultation = new HashSet<Consultation>();
    	}
     
    	public void addConsultation(Consultation pConsultation){
    		pConsultation.setPatientAppartientConsultation(this);
    		this.listConsultation.add(pConsultation);
    	}
     
    	// getters
    	public String getCaisseMaladie(){
    		return caisseMaladie;
    	}
     
    	public Date getDatePremVisite(){
    		return datePremVisite;
    	}
     
    	// setters
    	public void setCaisseMaladie(String pCaisseMaladie){
    		this.caisseMaladie = pCaisseMaladie;
    	}
     
    	public void setDatePremVisite(Date pDatePremVisite){		
    		this.datePremVisite = pDatePremVisite;
    	}
     
    }


    Merci encore à vous pour votre précieuse aide!

  10. #10
    Membre très actif
    Avatar de Khaled.Noordin
    Homme Profil pro
    Inscrit en
    Janvier 2005
    Messages
    354
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Janvier 2005
    Messages : 354
    Billets dans le blog
    1
    Par défaut
    hybride composite

  11. #11
    Membre confirmé
    Homme Profil pro
    graphisme & impression
    Inscrit en
    Mars 2011
    Messages
    118
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : graphisme & impression

    Informations forums :
    Inscription : Mars 2011
    Messages : 118
    Par défaut merci
    Citation Envoyé par Khaled.Noordin Voir le message
    hybride composite
    Hello,

    Merci je me documente sur la différence entre hybride et composite…
    Pour mon erreur là-haut tu aurais pas un idée par hasard?
    Je sèche vraiment

    Merci beaucoup.

  12. #12
    Membre confirmé
    Homme Profil pro
    graphisme & impression
    Inscrit en
    Mars 2011
    Messages
    118
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : graphisme & impression

    Informations forums :
    Inscription : Mars 2011
    Messages : 118
    Par défaut not null contraint
    Bonjour,

    Alors j'ai suivis la conférence (très intéressant) et lus la docs!
    Merci beaucoup c'était très informatif.

    Je n'arrive malheureusement toujours pas à solutionner mon problème:
    Quand je persit Patient, j'ai une erreur NOT NULL contraint on entitie.Patient-id?
    cf.

    Quelqu'un a-t-il une idée?

    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
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
     
     
     
    package entites;
     
    import java.io.Serializable;
    import java.util.Date;
     
    import javax.persistence.Column;
    import javax.persistence.EmbeddedId;
    import javax.persistence.Entity;
    import javax.persistence.FetchType;
    import javax.persistence.Id;
    import javax.persistence.IdClass;
    import javax.persistence.JoinColumn;
    import javax.persistence.JoinColumns;
    import javax.persistence.ManyToOne;
    import javax.persistence.PrimaryKeyJoinColumn;
    import javax.persistence.Table;
    import javax.persistence.Temporal;
    import javax.persistence.TemporalType;
     
     
    @SuppressWarnings("serial")
    @Entity
    @Table(name="consultation")
    public class Consultation implements Serializable{
     
     
    	@EmbeddedId
    	private ConsultationId id;
     
    	@Column(name="date", nullable = false, insertable=false, updatable=false)
    	@Temporal(TemporalType.TIMESTAMP)
    	private Date date;
     
    	@ManyToOne(fetch=FetchType.LAZY)
    	@JoinColumn(name = "patient_id", nullable = false, insertable=false, updatable=false)
    	private Patient patientAppartientConsultation;
     
    	@Column(name="remarque", nullable = true)
    	private String remarque;
     
    	public Consultation(Date pDate, String pRemarque){
    		this.id = new ConsultationId();
    		this.remarque = pRemarque;
    		setDate(pDate);
    	}
     
    	public ConsultationId getId() {
    		return id;
    	}
     
    	public void setId(ConsultationId id) {
    		this.id = id;
    	}
     
    	public Date getDate() {
    		return date;
    	}
     
    	public void setDate(Date date) {
    		this.date = date;
    		this.id.setDate(date);
    	}
     
    	public Patient getPatientAppartientConsultation() {
    		return patientAppartientConsultation;
    	}
     
    	public void setPatientAppartientConsultation(Patient patientAppartientConsultation) {
    		this.patientAppartientConsultation = patientAppartientConsultation;
    		this.id.setPatientAppartientConsultation(patientAppartientConsultation);
    	}
     
    	public String getRemarque() {
    		return remarque;
    	}
     
    	public void setRemarque(String remarque) {
    		this.remarque = remarque;
    	}
     
     
     
     
     
    }
     
    package entites;
     
    import java.io.Serializable;
    import java.util.Date;
     
    import javax.persistence.Column;
    import javax.persistence.Embeddable;
     
    @Embeddable
    public class ConsultationId implements Serializable{
     
    	private Date date;
     
    	private Patient  patientAppartientConsultation;
     
    	public Patient getPatientAppartientConsultation() {
    		return patientAppartientConsultation;
    	}
     
    	public void setPatientAppartientConsultation(Patient patientAppartientConsultation) {
    		this.patientAppartientConsultation = patientAppartientConsultation;
    	}
     
    	public Date getDate() {
    		return date;
    	}
     
    	public void setDate(Date date) {
    		this.date = date;
    	}
     
     
     
     
    }
     
    package entites;
     
    import java.io.Serializable;
     
    import java.util.Date;
    import java.util.HashSet;
    import java.util.Set;
     
    import javax.persistence.CascadeType;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.IdClass;
    import javax.persistence.OneToMany;
    import javax.persistence.Table;
    import javax.persistence.Temporal;
    import javax.persistence.TemporalType;
     
     
     
     
     
    @SuppressWarnings("serial")
    @Entity
    @Table(name="patient")
    public class Patient extends Personne implements Serializable{
     
     
    	@Column(name="caisseMaladie", length = 30, nullable = false)
    	private String caisseMaladie;
     
    	@Column(name="datePremVisite", nullable=true)
    	@Temporal(TemporalType.DATE)
    	private Date datePremVisite;
     
    	@OneToMany(mappedBy="patientAppartientConsultation", cascade = { CascadeType.ALL })
    	private Set<Consultation> listConsultation;
     
    	public Patient(String pPrenom, String pNom, String pProfession, Date pDateNaissance, String pNumeroTel, String pMail, 
    			String pCaisseMaladie, Date pDatePremVisite){
    		super(pPrenom, pNom, pProfession, pDateNaissance, pNumeroTel, pMail);
    		setCaisseMaladie(pCaisseMaladie);
    		setDatePremVisite(pDatePremVisite);
    		this.listConsultation = new HashSet<Consultation>();
    	}
     
    	public void addConsultation(Consultation pConsultation){
    		pConsultation.setPatientAppartientConsultation(this);
    		this.listConsultation.add(pConsultation);
    	}
     
    	// getters
    	public String getCaisseMaladie(){
    		return caisseMaladie;
    	}
     
    	public Date getDatePremVisite(){
    		return datePremVisite;
    	}
     
    	// setters
    	public void setCaisseMaladie(String pCaisseMaladie){
    		this.caisseMaladie = pCaisseMaladie;
    	}
     
    	public void setDatePremVisite(Date pDatePremVisite){		
    		this.datePremVisite = pDatePremVisite;
    	}
     
    }

  13. #13
    Membre très actif
    Avatar de Khaled.Noordin
    Homme Profil pro
    Inscrit en
    Janvier 2005
    Messages
    354
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Janvier 2005
    Messages : 354
    Billets dans le blog
    1
    Par défaut
    pour pouvoir persister ton entité possédant une clé composite, alors les entités qui composent ta clé (patient) doivent dans un premier appel à l'entity manager être persisté alors tu pourra persisté l'entité à clé composite.
    Dans ton cas j'aurais plus vue une clé unique sur le couple (patient,date) et resté sur une clé simple de type numérique auto incrémenté plutôt que ton schéma.
    si tu utilise un outils comme netbeans ou bien le plugin jpa de eclipse.
    Dans un premier temps crée ton modèle de données à partir du sql vers une base tel que mysql, et dans un second temps ensuite genere un mapping objet avec l'ide.
    Cela te montrera une possibilité de mappage.

  14. #14
    Membre confirmé
    Homme Profil pro
    graphisme & impression
    Inscrit en
    Mars 2011
    Messages
    118
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : graphisme & impression

    Informations forums :
    Inscription : Mars 2011
    Messages : 118
    Par défaut Merci
    Ok, merci!
    Le problème est résolu et mon code fonctionne…
    Je poste ma version si cela peut servir à quelqu'un …

    Merci pour tes conseils concernant la marche à suivre pour générer mon code.
    C'est vraiment une bonne idée!

    Bon dimanche

    P.-S. merci aussi pour la doc

    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
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
     
    package entites;
     
    import java.io.Serializable;
    import java.util.Date;
     
    import javax.persistence.CascadeType;
    import javax.persistence.Column;
    import javax.persistence.EmbeddedId;
    import javax.persistence.Entity;
    import javax.persistence.FetchType;
     
    import javax.persistence.JoinColumn;
    import javax.persistence.ManyToOne;
     
    import javax.persistence.Table;
    import javax.persistence.Temporal;
    import javax.persistence.TemporalType;
     
     
    import entites.clesCompose.ConsultationId;
     
     
    @SuppressWarnings("serial")
    @Entity
    @Table(name="consultation")
    public class Consultation implements Serializable{
     
     
    	@EmbeddedId
    	private ConsultationId id;
     
    	@Column(name="date", nullable = false, insertable=false, updatable=false)
    	@Temporal(TemporalType.TIMESTAMP)
    	private Date date;
     
     
    	@ManyToOne
    	@JoinColumn(name = "patient_id", nullable = false, insertable=false, updatable=false)
    	private Patient patientAppartientConsultation;
     
    	@Column(name="remarque", nullable = true)
    	private String remarque;
     
    	public Consultation(){}
     
    	public Consultation(Date pDate, String pRemarque){
    		this.id = new ConsultationId();
    		setRemarque(pRemarque);
    		setDate(pDate);
    	}
     
    	public ConsultationId getId() {
    		return id;
    	}
     
    	public void setId(ConsultationId id) {
    		this.id = id;
    	}
     
    	public Date getDate() {
    		return date;
    	}
     
    	public void setDate(Date date) {
    		this.date = date;
    		this.id.setDate(date);
    	}
     
    	public Patient getPatientAppartientConsultation() {
    		return patientAppartientConsultation;
    	}
     
    	public void setPatientAppartientConsultation(Patient patientAppartientConsultation) {
    		this.patientAppartientConsultation = patientAppartientConsultation;
    		this.id.setPatientAppartientConsultationId(patientAppartientConsultation.getId());
    	}
     
    	public String getRemarque() {
    		return remarque;
    	}
     
    	public void setRemarque(String remarque) {
    		this.remarque = remarque;
    	}
     
    package entites;
     
    import java.io.Serializable;
     
    import java.util.Date;
    import java.util.HashSet;
    import java.util.Set;
     
    import javax.persistence.CascadeType;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.IdClass;
    import javax.persistence.JoinColumn;
    import javax.persistence.JoinTable;
    import javax.persistence.ManyToMany;
    import javax.persistence.OneToMany;
    import javax.persistence.Table;
    import javax.persistence.Temporal;
    import javax.persistence.TemporalType;
     
     
     
     
     
    @SuppressWarnings("serial")
    @Entity
    @Table(name="patient")
    public class Patient extends Personne implements Serializable{
     
     
    	@Column(name="caisseMaladie", length = 30, nullable = false)
    	private String caisseMaladie;
     
    	@Column(name="datePremVisite", nullable=true)
    	@Temporal(TemporalType.DATE)
    	private Date datePremVisite;
     
    	@OneToMany(mappedBy="patientAppartientConsultation", cascade = { CascadeType.ALL })
    	private Set<Consultation> listConsultation;
     
    	@ManyToMany(cascade={CascadeType.PERSIST})
    	@JoinTable(name="patient_therapeute",joinColumns = @JoinColumn(name = "patient_id"), 
    	inverseJoinColumns = @JoinColumn(name = "therapeute_id"))
    	private Set<Therapeute> therapeutesAppartientPatient;
     
    	public Patient(){}
     
    	public Patient(String pPrenom, String pNom, String pProfession, Date pDateNaissance, String pNumeroTel, String pMail, 
    			String pCaisseMaladie, Date pDatePremVisite){
    		super(pPrenom, pNom, pProfession, pDateNaissance, pNumeroTel, pMail);
    		setCaisseMaladie(pCaisseMaladie);
    		setDatePremVisite(pDatePremVisite);
    		this.listConsultation = new HashSet<Consultation>();
    		this.therapeutesAppartientPatient = new HashSet<Therapeute>();
    	}
     
    	public void addConsultation(Consultation pConsultation){
    		this.listConsultation.add(pConsultation);
    	}
     
    	public void addTherapeutesAppartientPatient(Therapeute pTherapeute){
    		this.therapeutesAppartientPatient.add(pTherapeute);
    	}
     
    	// getters
    	public String getCaisseMaladie(){
    		return caisseMaladie;
    	}
     
    	public Date getDatePremVisite(){
    		return datePremVisite;
    	}
     
    	// setters
    	public void setCaisseMaladie(String pCaisseMaladie){
    		this.caisseMaladie = pCaisseMaladie;
    	}
     
    	public void setDatePremVisite(Date pDatePremVisite){		
    		this.datePremVisite = pDatePremVisite;
    	}
     
    }
     
     
     
    }
     
    package entites;
     
    import java.io.Serializable;
    import java.util.Date;
     
    import javax.persistence.CascadeType;
    import javax.persistence.Column;
    import javax.persistence.EmbeddedId;
    import javax.persistence.Entity;
    import javax.persistence.FetchType;
     
    import javax.persistence.JoinColumn;
    import javax.persistence.ManyToOne;
     
    import javax.persistence.Table;
    import javax.persistence.Temporal;
    import javax.persistence.TemporalType;
     
     
    import entites.clesCompose.ConsultationId;
     
     
    @SuppressWarnings("serial")
    @Entity
    @Table(name="consultation")
    public class Consultation implements Serializable{
     
     
    	@EmbeddedId
    	private ConsultationId id;
     
    	@Column(name="date", nullable = false, insertable=false, updatable=false)
    	@Temporal(TemporalType.TIMESTAMP)
    	private Date date;
     
     
    	@ManyToOne
    	@JoinColumn(name = "patient_id", nullable = false, insertable=false, updatable=false)
    	private Patient patientAppartientConsultation;
     
    	@Column(name="remarque", nullable = true)
    	private String remarque;
     
    	public Consultation(){}
     
    	public Consultation(Date pDate, String pRemarque){
    		this.id = new ConsultationId();
    		setRemarque(pRemarque);
    		setDate(pDate);
    	}
     
    	public ConsultationId getId() {
    		return id;
    	}
     
    	public void setId(ConsultationId id) {
    		this.id = id;
    	}
     
    	public Date getDate() {
    		return date;
    	}
     
    	public void setDate(Date date) {
    		this.date = date;
    		this.id.setDate(date);
    	}
     
    	public Patient getPatientAppartientConsultation() {
    		return patientAppartientConsultation;
    	}
     
    	public void setPatientAppartientConsultation(Patient patientAppartientConsultation) {
    		this.patientAppartientConsultation = patientAppartientConsultation;
    		this.id.setPatientAppartientConsultationId(patientAppartientConsultation.getId());
    	}
     
    	public String getRemarque() {
    		return remarque;
    	}
     
    	public void setRemarque(String remarque) {
    		this.remarque = remarque;
    	}
     
     
    }
     
    package entites.clesCompose;
     
    import java.io.Serializable;
    import java.util.Date;
     
    import javax.persistence.Column;
    import javax.persistence.Embeddable;
    import javax.persistence.JoinColumn;
     
    import entites.Patient;
     
    @Embeddable
    public class ConsultationId implements Serializable{
     
    	private Date date;
     
    	private int  patient_id;
     
     
     
    	public int getPatientAppartientConsultationId() {
    		return patient_id;
    	}
     
    	public void setPatientAppartientConsultationId(
    			int patientAppartientConsultationId) {
    		this.patient_id = patientAppartientConsultationId;
    	}
     
    	public Date getDate() {
    		return date;
    	}
     
    	public void setDate(Date date) {
    		this.date = date;
    	}
     
     
     
     
    }

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

Discussions similaires

  1. Problème identifié sur PC portable hp
    Par Berkut dans le forum Composants
    Réponses: 0
    Dernier message: 04/06/2009, 23h48
  2. Problème ' Identifier redeclared '
    Par revsys dans le forum Delphi
    Réponses: 5
    Dernier message: 25/04/2007, 15h26
  3. Réponses: 8
    Dernier message: 12/04/2007, 11h32
  4. [REDHAT] problème identifiant et mdp
    Par Doulim dans le forum RedHat / CentOS / Fedora
    Réponses: 4
    Dernier message: 13/01/2007, 14h46
  5. Problème identifiant hibernate
    Par kokumbo dans le forum Hibernate
    Réponses: 2
    Dernier message: 15/11/2006, 19h18

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