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 :

JPA [EclipseLink-63] erreur relation bidirectionnelle OneToMany


Sujet :

JPA Java

  1. #1
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2014
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 32
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2014
    Messages : 8
    Points : 7
    Points
    7
    Par défaut JPA [EclipseLink-63] erreur relation bidirectionnelle OneToMany
    Bonsoir à tous,
    S'il vous plait, j'ai besoin d'aide. J'essaie de créer, avec JPA, une relation bidirectionnelle OneToMany, mais j'ai les erreurs suivantes:
    "[EclipseLink-63] : The instance creation method [entity.OrderLine.], with no parameters, does not exist, or is not accessible. [EclipseLink-28019] : Deployment of PersistenceUnit [simple-jpaPU] failed. Close all factories for this PersistenceUnit."

    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
     
    package entity;
    import java.util.*;
    import java.io.Serializable;
    import javax.persistence.*;
    import org.eclipse.persistence.annotations.TimeOfDay;
     
    /**
     *
     * @author berra
     */
    @Entity
    public class Order implements Serializable {
     
        private static final long serialVersionUID = 1L;
        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        private Long id;
        @Temporal(TemporalType.TIMESTAMP)
        private Date creationDate;    
        @OneToMany(mappedBy = "o")
        private   List<OrderLine>  orderLines; 
     
        public Date getCreationDate() {
            return creationDate;
        }
     
        public void setCreationDate(Date creationDate) {
            this.creationDate = creationDate;
        }
     
        public List<OrderLine> getOrderLines() {
            return orderLines;
        }
     
        public void setOrderLines(ArrayList<OrderLine> orderLines) {
            this.orderLines = orderLines;
        }
     
        public Order(Date creationDate) {
            this.creationDate = creationDate;
        }
     
     
     
     
     
        public Long getId() {
            return id;
        }
     
        public void setId(Long id) {
            this.id = id;
        }
     
        @Override
        public int hashCode() {
            int hash = 0;
            hash += (id != null ? id.hashCode() : 0);
            return hash;
        }
     
        @Override
        public boolean equals(Object object) {
            // TODO: Warning - this method won't work in the case the id fields are not set
            if (!(object instanceof Order)) {
                return false;
            }
            Order other = (Order) object;
            if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
                return false;
            }
            return true;
        }
     
        @Override
        public String toString() {
            return "entity.Order[ id=" + id + " ]";
        }
     
    }
    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
     
    package entity;
     
    import java.io.Serializable;
    import javax.persistence.*;
     
    /**
     *
     * @author berra
     */
    @Entity
    @Table(name="orderline_table")
    public class OrderLine implements Serializable {
     
        private static final long serialVersionUID = 1L;
        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        private Long id;
     
        private String item; 
        private  Double unitPrice;   
        private Integer quantity;
     
        @ManyToOne
        Order o; 
     
        public String getItem() {
            return item;
        }
     
        public void setItem(String item) {
            this.item = item;
        }
     
        public Double getUnitPrice() {
            return unitPrice;
        }
     
        public void setUnitPrice(Double unitPrice) {
            this.unitPrice = unitPrice;
        }
     
        public Integer getQuantity() {
            return quantity;
        }
     
        public void setQuantity(Integer quantity) {
            this.quantity = quantity;
        }
     
        public OrderLine(String item, Double unitPrice, Integer quantity) {
            this.item = item;
            this.unitPrice = unitPrice;
            this.quantity = quantity;
        }
     
     
     
        public Long getId() {
            return id;
        }
     
        public void setId(Long id) {
            this.id = id;
        }
     
        @Override
        public int hashCode() {
            int hash = 0;
            hash += (id != null ? id.hashCode() : 0);
            return hash;
        }
     
        @Override
        public boolean equals(Object object) {
            // TODO: Warning - this method won't work in the case the id fields are not set
            if (!(object instanceof OrderLine)) {
                return false;
            }
            OrderLine other = (OrderLine) object;
            if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
                return false;
            }
            return true;
        }
     
        @Override
        public String toString() {
            return "entity.OrderLine[ id=" + id + " ]";
        }
     
    }
    S'il vous plait, est-ce que quelqu'un peut m'aider ?

  2. #2
    Membre habitué
    Profil pro
    Inscrit en
    Décembre 2005
    Messages
    265
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2005
    Messages : 265
    Points : 181
    Points
    181
    Par défaut pb OrderLine
    Ca semble pas grave.

    Pour ta classe OrderLine, il te faut une methode constructeur sans argument rajouter

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    Class OrderLine implements ... {
    ..
     
    public OrderLine () {
    }
     
    ...
    Ca devrait lever ton erreur.


  3. #3
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2014
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 32
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2014
    Messages : 8
    Points : 7
    Points
    7
    Par défaut JPA [EclipseLink-4002] erreur relation bidirectionnelle OneToMany
    Merci beaucoup, j'ai pû lever l'erreur. Mais maintenant, j'ai cette erreur :
    "[EclipseLink-4002] : PSQLException: ERREUR: erreur de syntaxe sur ou près de « ORDER »"

    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
     
    package entity;
     
    /**
     *
     * @author berra
     */
    import entity.Book;
    import java.util.*;
    import javax.persistence.*;
    public class Demo {
     
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            OrderLine ol1 = new OrderLine("Camera", 552.30, 25);
            OrderLine ol2 = new OrderLine("Portable", 5752.45, 35);
            Order o1 = new Order(new Date(2017, 20, 5));
            ArrayList <OrderLine> l1 = new ArrayList<OrderLine>();
            l1.add(ol1);
            l1.add(ol2);
            o1.setOrderLines(l1);
            persist(o1);
        }
     
        private static void persist(Object object) {
            EntityManagerFactory emf = javax.persistence.Persistence.createEntityManagerFactory("simple-jpaPU");
            EntityManager em = emf.createEntityManager();
            em.getTransaction().begin();
            try{
                em.persist(object);
                em.getTransaction().commit();
            }
            catch(Exception e){
                e.printStackTrace();
                em.getTransaction().rollback();
            }
            finally{
                em.close();
            }
        }
     
    }

  4. #4
    Membre habitué
    Profil pro
    Inscrit en
    Décembre 2005
    Messages
    265
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2005
    Messages : 265
    Points : 181
    Points
    181
    Par défaut pb PSQLException
    Je sais que c pas evident à résoudre.

    Tu as bien construit ta relation? Ton mappage est il cohérent?

    Il semble qu'il y ait une incohérence avec ta bdd. Après je suis pas expert la-dedans.
    Inspecte ta base...


    Bonne chance

  5. #5
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2014
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 32
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2014
    Messages : 8
    Points : 7
    Points
    7
    Par défaut JPA [EclipseLink-63] erreur relation bidirectionnelle OneToMany
    Merci beaucoup : )

  6. #6
    Nouveau membre du Club
    Homme Profil pro
    Développeur Java
    Inscrit en
    Décembre 2015
    Messages
    21
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Indre et Loire (Centre)

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Décembre 2015
    Messages : 21
    Points : 37
    Points
    37
    Par défaut
    Bonjour a toi,

    Méfie toi ORDER(non case-sensitive) est un mot clé réservé en SQL, hors une de tes classe s'appelle order je te conseille de changer de nom si tu ne veux pas avoir des erreurs sortant de l'espace temps écrite en allemands sur 18 pages de logs...

    A bon entendeur

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

Discussions similaires

  1. Réponses: 2
    Dernier message: 25/08/2009, 16h30
  2. [EJB3 Entity] Suppression et relation bidirectionnelle
    Par KillThatGirl dans le forum Java EE
    Réponses: 1
    Dernier message: 31/01/2009, 18h08
  3. [Modèle Relationnel] Relations bidirectionnelles entre 3 tables
    Par Tchupacabra dans le forum Schéma
    Réponses: 2
    Dernier message: 06/11/2008, 14h31
  4. Réponses: 1
    Dernier message: 14/08/2008, 19h23
  5. JPA - Relation bidirectionnel
    Par JoloKossovar dans le forum JPA
    Réponses: 3
    Dernier message: 26/05/2008, 13h54

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