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 :

Mapping entity


Sujet :

JPA Java

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Mai 2007
    Messages
    52
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2007
    Messages : 52
    Points : 61
    Points
    61
    Par défaut Mapping entity
    Bonjour voici mon probleme :
    j'ai une bd oracle existante qui possede les tables et les champs suivants:
    *C_BPartner (business partner )
    idbpartner
    name
    *C_Location
    idlocation
    *C_BPartner_Location
    idBPartnerLocation
    idlocation
    idbpartner

    J'ai 2 entity bean type 3.0.
    relation 1-n entre C_BPartner et C_BPartner_Location
    1-1 entre C_BPartner_Location et C_Location

    J'ai utilisé les annotations
    @OneToMany
    @JoinTable

    mais en vain, quelqu'un a t'il deja expérimenté ca ?

  2. #2
    Expert éminent
    Avatar de djo.mos
    Profil pro
    Inscrit en
    Octobre 2004
    Messages
    4 666
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2004
    Messages : 4 666
    Points : 7 679
    Points
    7 679
    Par défaut
    Bonjour,
    Montre nous ce que tu as fait et en quoi ça marche pas.


  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Mai 2007
    Messages
    52
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2007
    Messages : 52
    Points : 61
    Points
    61
    Par défaut
    Voici mon 1e bean :

    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
    package entity;
    import java.io.Serializable;
    import javax.persistence.Entity;
    import javax.persistence.Id;
    import javax.persistence.Column;
    import javax.persistence.OneToMany;
    import javax.persistence.Table;
    import static javax.persistence.FetchType.LAZY;
     
    @Entity
    @Table(name="C_LOCATION")
    public class Location implements Serializable {
     
    	private BPartner bpartner;
    	private int idLocation;
    	private String address1;
     
    	@Id
    	@Column(name="C_LOCATION_ID")
    	public int getIdLocation() {
    		return idLocation;
    	}
    	public void setIdLocation(int idLocation) {
    		this.idLocation = idLocation;
    	}
     
    	@Column(name="ADDRESS1")
    	public String getAddress1() {
    		return address1;
    	}
    	public void setAddress1(String address1) {
    		this.address1 = address1;
    	}
     
    	@OneToOne(mappedBy="locations") //erreur         <------------------------
    	public BPartner getBpartner() {
    		return bpartner;
    	}
    	public void setBpartner(BPartner bpartner) {
    		this.bpartner = bpartner;
    	}
    }






    Et le deuxième :


    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
    package entity;
    import java.io.Serializable;
    import java.util.ArrayList;
    import java.util.Collection;
    import javax.persistence.*;
     
    import org.hibernate.validator.NotNull;
    import static javax.persistence.CascadeType.MERGE;
    import static javax.persistence.FetchType.EAGER;
     
     
    @Entity
    @Table(name="C_BPARTNER")
     
    public class BPartner  implements Serializable {
     
    	private static final long serialVersionUID = 1L;
    	private int c_bpartner_id;
    	private String name;
    	private ArrayList<Location> locations ;
     
    	@OneToMany
    	@JoinTable(name="C_BPARTNER_LOCATION", joinColumns = @JoinColumn(name="C_BPARTNER_ID", referencedColumnName = "C_BPARTNER_ID"), inverseJoinColumns = @JoinColumn(name="C_LOCATION_ID", referencedColumnName = "C_LOCATION_ID"))
    	public ArrayList<Location> getLocations() {
    		return locations;
    	}
     
    	public void setLocations(ArrayList<Location> locations) {
    		this.locations = locations;
    	}
     
    	@Id
    	@Column(name = "C_BPARTNER_ID")
    	@NotNull
    	public int getC_bpartner_id() {
    		return c_bpartner_id;
    	}
     
    	@Column(name = "NAME")
    	public String getName() {
    		return name;
    	}
     
    	public void setC_bpartner_id(int id) {
    		this.c_bpartner_id = id;
    	}
     
    	public void setName(String name) {
    		this.name = name;
    	}
     
    }

  4. #4
    Membre du Club
    Profil pro
    Inscrit en
    Mai 2007
    Messages
    52
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2007
    Messages : 52
    Points : 61
    Points
    61
    Par défaut
    le fetch était lazy par défaut mais plus de session en cours. C'est pour ca que ca donnait une erreur.
    j'ai donc remplacé par Eager (pdt chargement de l'entité)

    J'ai trouvé.

    @OneToMany(fetch = EAGER)
    @JoinTable(
    name="C_BPARTNER_LOCATION",
    joinColumns = { @JoinColumn( name="C_BPARTNER_ID") },
    inverseJoinColumns = @JoinColumn( name="C_LOCATION_ID")
    )

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

Discussions similaires

  1. mapping entity sur lui meme
    Par MattA184575 dans le forum JPA
    Réponses: 7
    Dernier message: 03/02/2009, 13h54
  2. EJB Entity Bean et problème de mapping
    Par bard123 dans le forum JPA
    Réponses: 13
    Dernier message: 07/03/2008, 08h54
  3. EJB Entity : mapping O/R de String
    Par fatypunk dans le forum JPA
    Réponses: 2
    Dernier message: 04/02/2008, 14h33
  4. Réponses: 1
    Dernier message: 28/04/2007, 20h26
  5. mapping et entity class not found
    Par mauroyb0 dans le forum Hibernate
    Réponses: 8
    Dernier message: 26/03/2007, 14h39

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