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

JSF Java Discussion :

Utiliser des objets comme clé primaire composée en JPA


Sujet :

JSF Java

  1. #1
    Nouveau membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2013
    Messages
    32
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Burkina Faso

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2013
    Messages : 32
    Points : 28
    Points
    28
    Par défaut Utiliser des objets comme clé primaire composée en JPA
    Bonjour à tous, j'aimerais solliciter votre aide pour résoudre un problème en JPA.
    En fait j'ai une table Participation en MySQL qui contient une une clé primaire composite referant la clé primaire de la table Utilisateur et la clé primaire de la table EspaceTravail. Dans mon projet j'ai déjà créé les entités Utilisateur et EspaceTravail mais pour l'entité Participation j'ai créé une classe MyParticipationKey
    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
     
    @Embeddable
    public class MyParticipationKey implements Serializable {
     	/**
             * 
             */
    	private static final long serialVersionUID = 1L;
    	@Column(name="	pkIduser")
    	private Utilisateur utilisateur;
    	@Column(name="	pkIdet")
        private EspaceTravail espaceTravail;
     
    	public Utilisateur getUtilisateur() {
    		return utilisateur;
    	}
    	public void setUtilisateur(Utilisateur utilisateur) {
    		this.utilisateur = utilisateur;
    	}
    	public EspaceTravail getEspaceTravail() {
    		return espaceTravail;
    	}
    	public void setEspaceTravail(EspaceTravail espaceTravail) {
    		this.espaceTravail = espaceTravail;
    	}   
    }
     
    @Entity
    @ManagedBean
    public class Participation {
    	@EmbeddedId
    	MyParticipationKey myParticipationKey;
     
    	public MyParticipationKey getMyParticipationKey() {
    		return myParticipationKey;
    	}
     
    	public void setMyParticipationKey(MyParticipationKey myParticipationKey) {
    		this.myParticipationKey = myParticipationKey;
    	}
     
    }
    Alors quand je fais et que j'execute Eclipse m'affiche ce message:
    Exception Description: The mapping [espaceTravail] from the embedded ID class [class gct.entities.MyParticipationKey] is an invalid mapping for this class. An embeddable class that is used with an embedded ID specification (attribute [myParticipationKey] from the source [class gct.entities.Participation]) can only contain basic mappings. Either remove the non basic mapping or change the embedded ID specification on the source to be embedded.
    Je vous remercie pour vos différentes suggestions.Merci

  2. #2
    Membre averti
    Homme Profil pro
    Inscrit en
    Octobre 2011
    Messages
    250
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2011
    Messages : 250
    Points : 403
    Points
    403
    Par défaut
    Remplace @EmbeddedId par @Id, cela suffira

  3. #3
    Nouveau membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2013
    Messages
    32
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Burkina Faso

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2013
    Messages : 32
    Points : 28
    Points
    28
    Par défaut
    j'ai testé mais ça marche pas.Merci

  4. #4
    Membre chevronné Avatar de jeffray03
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2008
    Messages
    1 501
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Allemagne

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 501
    Points : 2 120
    Points
    2 120
    Par défaut
    salut,
    il te dit que:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    @Column(name="	pkIdet")
        private EspaceTravail espaceTravail;
    est un mapping invalid pour cette classe.
    peux-tu nous montrer le contenu de EspaceTravail.java

    Eric

  5. #5
    Nouveau membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2013
    Messages
    32
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Burkina Faso

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2013
    Messages : 32
    Points : 28
    Points
    28
    Par défaut
    Je m'excuse pour le retard et vous remercie d'avance pour vos différentes propositions de solutions. Voici le code de EspaceTravail
    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
     
    @Entity
    @ManagedBean
    public class EspaceTravail implements Serializable{
    	/**
             * 
             */
    	private static final long serialVersionUID = 1L;
    	@Id
    	@GeneratedValue( strategy = GenerationType.IDENTITY )
    	private Long pkIdet;
    	@NotNull(message="Veuillez remplir le nom")
    	@Size(min=3,message="Le nom doit contenir au moins 3 caractères!")
    	private String nom;
    	private String type;
    	private String description;
    	private String statut;
    	@ManyToOne
    	@JoinColumn(name="pkIduser")
    	private Utilisateur utilisateur;
     
    	public Utilisateur getUtilisateur() {
    		return utilisateur;
    	}
    	public void setUtilisateur(Utilisateur utilisateur) {
    		this.utilisateur = utilisateur;
    	}
    	public String getStatut() {
    		return statut;
    	}
    	public void setStatut(String statut) {
    		this.statut = statut;
    	}
    	public Long getPkIdet() {
    		return pkIdet;
    	}
    	public void setPkIdet(Long pkIdet) {
    		this.pkIdet = pkIdet;
    	}
    	public String getNom() {
    		return nom;
    	}
    	public void setNom(String nom) {
    		this.nom = nom;
    	}
    	public String getType() {
    		return type;
    	}
    	public void setType(String type) {
    		this.type = type;
    	}
    	public String getDescription() {
    		return description;
    	}
    	public void setDescription(String description) {
    		this.description = description;
    	}
    }
    Merci à vous!

  6. #6
    Membre chevronné Avatar de jeffray03
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2008
    Messages
    1 501
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Allemagne

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 501
    Points : 2 120
    Points
    2 120
    Par défaut
    salut,
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    @Column(name="	pkIdet")
        private EspaceTravail espaceTravail;
    par:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    @OneToMany
    @JoinColumn(name="pkIdet")
    private EspaceTravail espaceTravail;
    montres nous ou tu utilises ta classe @embeddable.

    Eric

  7. #7
    Nouveau membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2013
    Messages
    32
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Burkina Faso

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2013
    Messages : 32
    Points : 28
    Points
    28
    Par défaut
    j'ai créé une classe Participation

    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
     
    @Entity
    @ManagedBean
    public class Participation {
    	@EmbeddedId
    	MyParticipationKey myParticipationKey;
     
    	public MyParticipationKey getMyParticipationKey() {
    		return myParticipationKey;
    	}
     
    	public void setMyParticipationKey(MyParticipationKey myParticipationKey) {
    		this.myParticipationKey = myParticipationKey;
    	}
     
    }

  8. #8
    Membre chevronné Avatar de jeffray03
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2008
    Messages
    1 501
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Allemagne

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 501
    Points : 2 120
    Points
    2 120
    Par défaut
    salut,
    remplace :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    @EmbeddedId
    	MyParticipationKey myParticipationKey;
    par:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    @EmbeddedId
    	@AttributeOverrides({
    			@AttributeOverride(name = "utilisateur", column = @Column(name = "User_ID")),
    			@AttributeOverride(name = "espaceTravail", column = @Column(name = "ESP_ID")) })
    	MyParticipationKey myParticipationKey;
    eric

  9. #9
    Nouveau membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2013
    Messages
    32
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Burkina Faso

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2013
    Messages : 32
    Points : 28
    Points
    28
    Par défaut
    Bonjour j'ai testé ta solution mais ça ne marche pas.
    voici mon code
    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
     
    @Entity
    @ManagedBean
    public class Participation {
    	@EmbeddedId
    	@AttributeOverrides({
    			@AttributeOverride(name = "utilisateur", column=@Column(name = "pkIduser")),
    			@AttributeOverride(name = "espaceTravail", column = @Column(name = "pkIdet")) })
    	MyParticipationKey myParticipationKey;
     
    	public MyParticipationKey getMyParticipationKey() {
    		return myParticipationKey;
    	}
     
    	public void setMyParticipationKey(MyParticipationKey myParticipationKey) {
    		this.myParticipationKey = myParticipationKey;
    	}
     
    }

  10. #10
    Membre chevronné Avatar de jeffray03
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2008
    Messages
    1 501
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Allemagne

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 501
    Points : 2 120
    Points
    2 120
    Par défaut
    il t´affiche quoi comme erreur?

    Eric

  11. #11
    Nouveau membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2013
    Messages
    32
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Burkina Faso

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2013
    Messages : 32
    Points : 28
    Points
    28
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    The attribute named [espaceTravail] from the embeddable class
     [class gct.entities.MyParticipationKey] is not a valid mapping to use 
    with an attribute override for the attribute [myParticipationKey] on class [class gct.entities.Participation].

  12. #12
    Membre chevronné Avatar de jeffray03
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2008
    Messages
    1 501
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Allemagne

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 501
    Points : 2 120
    Points
    2 120
    Par défaut
    salut,
    remplaces :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    public class Participation
    par
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    public class Participation implements Serializable

  13. #13
    Nouveau membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2013
    Messages
    32
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Burkina Faso

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2013
    Messages : 32
    Points : 28
    Points
    28
    Par défaut
    L'exception s'affiche toujours!

Discussions similaires

  1. Réponses: 3
    Dernier message: 24/02/2007, 00h04
  2. Utilisation des objets COM
    Par jdelges dans le forum Général Dotnet
    Réponses: 1
    Dernier message: 26/01/2007, 23h52
  3. Utiliser des objets automation dans Oracle
    Par WebPac dans le forum Forms
    Réponses: 10
    Dernier message: 29/11/2006, 19h17
  4. Utiliser des objets SWING dans une vue RCP
    Par manuga72 dans le forum Eclipse Platform
    Réponses: 1
    Dernier message: 20/10/2006, 17h26
  5. Erreur lors de l' utilisation des objets ADO
    Par aityahia dans le forum Bases de données
    Réponses: 10
    Dernier message: 24/03/2006, 13h46

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