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 :

Correspondance xml et annotation


Sujet :

JPA Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Homme Profil pro
    Ingénieur Informatique et Réseaux
    Inscrit en
    Avril 2011
    Messages
    232
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur Informatique et Réseaux
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2011
    Messages : 232
    Par défaut Correspondance xml et annotation
    Bonjour,

    Je n'arrive pas trouver l'équivalence en annotation de ce fichier xml avec l'utilisation d'une EventList de la librairie GlazedList.
    J'ai lu qu'il faut utiliser collection-type="ca.odell.glazedlists.hibernate.EventListType" mais j'ai toujours l'erreur suivante:
    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
    javax.persistence.PersistenceException: [PersistenceUnit: BasketBallTrainerPU] Unable to configure EntityManagerFactory
    	at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:265)
    	at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:125)
    	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:110)
    	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)
    	at gmo.basketballtrainer.utils.HibernateUtil.<clinit>(HibernateUtil.java:19)
    Caused by: org.hibernate.AnnotationException: Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @CollectionOfElements: gmo.basketballtrainer.model.Evolution.drawableList
    	at org.hibernate.cfg.annotations.CollectionBinder.getCollectionBinder(CollectionBinder.java:264)
    	at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1455)
    	at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:754)
    	at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:534)
    	at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:286)
    	at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1115)
    	at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1225)
    	at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:159)
    	at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:854)
    	at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:191)
    	at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:253)
    	... 4 more
     
     
     The following providers:
    oracle.toplink.essentials.PersistenceProvider
    oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider
    Returned null to createEntityManagerFactory.
     
    	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:154)
    	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)
    	at gmo.basketballtrainer.utils.HibernateUtil.<clinit>(HibernateUtil.java:19)
    Exception in thread "main" Java Result: 1
    BUILD SUCCESSFUL (total time: 2 seconds)
    Mon fichier xml qui fonctionne:
    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
    <hibernate-mapping>
        <class name="gmo.basketballtrainer.model.Evolution" table="Evolution">
            <id name="id" type="int" column="id">
                <generator class="increment"/>
            </id>
            <property name="name" column="name"/>
            <property name="evolutionTime" column="evolutionTime"/>
            <property name="principe" column="principe"/>
            <property name="requirement" column="requirement"/>
            <property name="evolutionImage" column="evolutionImage"/>
            <list name="drawableList" cascade="all" collection-type="ca.odell.glazedlists.hibernate.EventListType">
                <key column="evolution_id"/>
                <list-index column="idx"/>
                <one-to-many class="gmo.basketballtrainer.model.drawableabstract.Drawable"/>
            </list>
        </class>
    </hibernate-mapping>
    L'équivalence en annotation:

    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
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package gmo.basketballtrainer.model;
     
    import ca.odell.glazedlists.BasicEventList;
    import ca.odell.glazedlists.EventList;
    import gmo.basketballtrainer.model.drawableabstract.Drawable;
    import java.io.Serializable;
    import javax.persistence.*;
    import org.hibernate.annotations.Index;
    import org.hibernate.annotations.Type;
     
    /**
     *
     * @author Spiritkill
     */
    @Entity
    public class Evolution implements Serializable {
     
        @Id
        @GeneratedValue(strategy=GenerationType.AUTO)
        private Integer id;
        private String name;
        private int evolutionTime;
        private String principe;
        private String requirement;
        @OneToMany(mappedBy = "evolution",cascade= CascadeType.ALL)
        @Type(type="ca.odell.glazedlists.hibernate.EventListType")
        @Index(name="idx")
        private EventList<Drawable> drawableList;
        private String evolutionImage;
        @ManyToOne
        private Exercise exercise;
     
        public Evolution() {
            this.name = "Evolution";
            this.evolutionTime = 0;
            this.principe = "";
            this.requirement = "";
            this.drawableList = new BasicEventList<>();
        }
     
        public Evolution(Exercise exercise, String name, int evolutionTime, String principe, String requirement, EventList<Drawable> drawableList) {
            this.name = name;
            this.evolutionTime = evolutionTime;
            this.principe = principe;
            this.requirement = requirement;
            this.drawableList = drawableList;
        }
     
        public EventList<Drawable> getDrawableList() {
            return drawableList;
        }
     
        public void setDrawableList(EventList<Drawable> drawableList) {
            this.drawableList = drawableList;
        }
     
        public int getEvolutionTime() {
            return evolutionTime;
        }
     
        public void setEvolutionTime(int evolutionTime) {
            this.evolutionTime = evolutionTime;
        }
     
        public String getName() {
            return name;
        }
     
        public void setName(String name) {
            this.name = name;
        }
     
        public String getEvolutionImage() {
            return evolutionImage;
        }
     
        public void setEvolutionImage(String evolutionImage) {
            this.evolutionImage = evolutionImage;
        }
     
        public String getPrincipe() {
            return principe;
        }
     
        public void setPrincipe(String principe) {
            this.principe = principe;
        }
     
        public String getRequirement() {
            return requirement;
        }
     
        public void setRequirement(String requirement) {
            this.requirement = requirement;
        }
     
        public Integer getId() {
            return id;
        }
     
        public void setId(Integer id) {
            this.id = id;
        }
     
        @Override
        public String toString() {
            return name;
        }
    }
    Merci.

  2. #2
    Membre éclairé
    Homme Profil pro
    Ingénieur Informatique et Réseaux
    Inscrit en
    Avril 2011
    Messages
    232
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur Informatique et Réseaux
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2011
    Messages : 232
    Par défaut
    Du coup j'ai redéfini certaine fonction de ListModel.
    Voir ce post: Evènement sur List et JList

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

Discussions similaires

  1. configuration : XML versus annotations
    Par loicmidy dans le forum Hibernate
    Réponses: 0
    Dernier message: 22/05/2010, 15h13
  2. XML ou Annotation
    Par benyahia4 dans le forum Spring
    Réponses: 1
    Dernier message: 15/03/2010, 17h06
  3. Mapping xml et annotation
    Par Sun03 dans le forum Hibernate
    Réponses: 1
    Dernier message: 22/06/2009, 21h20
  4. fichier xml vs annotations
    Par ganga dans le forum Langage
    Réponses: 5
    Dernier message: 04/03/2009, 11h48
  5. XML Schema correspondance code = valeur
    Par hipchic dans le forum Valider
    Réponses: 2
    Dernier message: 15/07/2005, 12h56

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