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

Hibernate Java Discussion :

Classe abstraite implémentant TreeNode [Mapping]


Sujet :

Hibernate 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 Classe abstraite implémentant TreeNode
    Bonjour,

    Je vous contact car je n'arrive pas à trouver le bon mapping (dans les fichier xml) pour 2 de mes classes: Exercise et Theme qui héritent d'une classe abstraite implémentant TreeNode.
    Voici l'implémentation des mes classes (elles sont corrects vue qu'avec les annotations cela fonctionnait)

    MyTreeNode:
    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
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package gmo.basketballtrainer.impl;
     
    import ca.odell.glazedlists.EventList;
    import javax.swing.tree.TreeNode;
     
    /**
     *
     * @author Spiritkill
     */
    public abstract class MyTreeNode implements TreeNode {
     
        protected Integer id;
        protected MyTreeNode father;
        protected EventList<MyTreeNode> childList;
     
        public EventList<MyTreeNode> getChildList() {
            return childList;
        }
     
        public void setChildList(EventList<MyTreeNode> childList) {
            this.childList = childList;
        }
     
        public MyTreeNode getFather() {
            return father;
        }
     
        public void setFather(MyTreeNode father) {
            this.father = father;
        }
     
        public Integer getId() {
            return id;
        }
     
        public void setId(Integer id) {
            this.id = id;
        }
    }
    Theme:
    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
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package gmo.basketballtrainer.model;
     
    //import gmo.basketballtrainer.impl.MyTreeNode;
    import ca.odell.glazedlists.BasicEventList;
    import ca.odell.glazedlists.EventList;
    import gmo.basketballtrainer.impl.MyTreeNode;
    import java.util.Enumeration;
    import javax.swing.tree.TreeNode;
     
    /**
     *
     * @author Spiritkill
     */
    public class Theme extends MyTreeNode {
     
        private String name;
     
        public Theme() {
            this.father = null;
            this.childList = new BasicEventList<>();
            this.name = "Thème";
        }
     
        public Theme(String name, EventList<MyTreeNode> childList, MyTreeNode father) {
            super();
            this.name = name;
            this.father = father;
            this.childList = childList;
        }
     
        public String getName() {
            return name;
        }
     
        public void setName(String name) {
            this.name = name;
        }
     
        @Override
        public String toString() {
            return this.name;
        }
     
        @Override
        public Enumeration<TreeNode> children() {
            return null;
        }
     
        @Override
        public boolean getAllowsChildren() {
            return true;
        }
     
        @Override
        public TreeNode getChildAt(int childIndex) {
            return childList.get(childIndex);
        }
     
        @Override
        public int getChildCount() {
            return childList.size();
        }
     
        @Override
        public int getIndex(TreeNode node) {
            return childList.indexOf(node);
        }
     
        @Override
        public TreeNode getParent() {
            return this.father;
        }
     
        @Override
        public boolean isLeaf() {
            return false;
        }
    }
    Exercise:
    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
    /*
     * 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.impl.MyTreeNode;
    import java.util.Enumeration;
    import javax.swing.tree.TreeNode;
     
    /**
     *
     * @author Spiritkill
     */
    public class Exercise extends MyTreeNode {
     
        private static final long serialVersionUID = 1L;
        private String name;
        private int actifPlayers;
        private String materials;
        private int exerciseTime;
        private EventList<Evolution> evolutionList;
        private EventList<Training> trainingList;
     
        public Exercise() {
            this.father = null;
            this.childList = new BasicEventList<>();
            this.name = "Exercise";
            this.actifPlayers = 0;
            this.materials = "";
            this.exerciseTime = 0;
            this.evolutionList = new BasicEventList();
            this.trainingList =  new BasicEventList<>();
        }
     
        public Exercise(String name, int actifPlayers, String materials, int exerciseTime, EventList<Evolution> evolutionList, EventList<Training> trainingList) {
            this.name = name;
            this.actifPlayers = actifPlayers;
            this.materials = materials;
            this.exerciseTime = exerciseTime;
            this.evolutionList = evolutionList;
            this.trainingList = trainingList;
        }
     
        public int getActifPlayers() {
            return actifPlayers;
        }
     
        public void setActifPlayers(int actifPlayers) {
            this.actifPlayers = actifPlayers;
        }
     
        public void addEvolution(Evolution evolution){
            this.evolutionList.add(evolution);
        }
     
        public void removeEvolution(Evolution evolution){
            this.evolutionList.remove(evolution);
        }
     
        public void removeEvolution(int index){
            this.evolutionList.remove(index);
        }
     
        public EventList<Evolution> getEvolutionList() {
            return evolutionList;
        }
     
        public void setEvolutionList(EventList<Evolution> evolutionList) {
            this.evolutionList = evolutionList;
        }
     
        public int getExerciseTime() {
            return exerciseTime;
        }
     
        public void setExerciseTime(int exerciseTime) {
            this.exerciseTime = exerciseTime;
        }
     
        public String getMaterials() {
            return materials;
        }
     
        public void setMaterials(String materials) {
            this.materials = materials;
        }
     
        public String getName() {
            return name;
        }
     
        public void setName(String name) {
            this.name = name;
        }
     
        @Override
        public String toString() {
            return name;
        }
     
        @Override
        public Enumeration<TreeNode> children() {
            return null;
        }
     
        @Override
        public boolean getAllowsChildren() {
            return false;
        }
     
        @Override
        public TreeNode getChildAt(int childIndex) {
            return childList.get(childIndex);
        }
     
        @Override
        public int getChildCount() {
            return childList.size();
        }
     
        @Override
        public int getIndex(TreeNode node) {
            return childList.indexOf(node);
        }
     
        @Override
        public TreeNode getParent() {
            return father;
        }
     
        @Override
        public boolean isLeaf() {
            return true;
        }
     
        public EventList<Training> getTrainingList() {
            return trainingList;
        }
     
        public void setTrainingList(EventList<Training> trainingList) {
            this.trainingList = trainingList;
        }
    }
    Voici mon .xml
    MyTreeNod.hbm.xml:
    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
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <hibernate-mapping>
        <class name="gmo.basketballtrainer.impl.MyTreeNode" abstract="true">
            <id name="id" type="int" column="id">
                <generator class="increment"/>
            </id>
            <many-to-one name="father" column="father_id"/>
            <list name="childList" cascade="all" collection-type="ca.odell.glazedlists.hibernate.EventListType">
                <key column="father_id"/>
                <list-index column="idx"/>
                <one-to-many class="gmo.basketballtrainer.impl.MyTreeNode"/>
            </list>
            <union-subclass name="gmo.basketballtrainer.model.Theme" table="Theme">
                <property name="name" column="name"/>
            </union-subclass>
            <union-subclass name="gmo.basketballtrainer.model.Exercise" table="Exercise">
                <property name="name" column="name"/>
                <property name="actifPlayers" column="actifPlayers"/>
                <property name="materials" column="materials"/>
                <property name="exerciseTime" column="exerciseTime"/>
                <list name="evolutionList" collection-type="ca.odell.glazedlists.hibernate.EventListType">
                    <key column="exercise_id"/>
                    <list-index column="idx"/>
                    <one-to-many class="gmo.basketballtrainer.model.Evolution"/>
                </list>
            </union-subclass>
        </class>
    </hibernate-mapping>
    La création des tables fonctionne mais que je veux enregistrer mon Theme avec un Exercise comme child l'erreur me dit que la table MyTreeNode n'existe pas.
    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
    Grave: Could not synchronize database state with session
    org.hibernate.exception.SQLGrammarException: could not insert collection rows: [gmo.basketballtrainer.impl.MyTreeNode.childList#1]
    	at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
    	at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
    	at org.hibernate.persister.collection.AbstractCollectionPersister.insertRows(AbstractCollectionPersister.java:1394)
    	at org.hibernate.action.CollectionUpdateAction.execute(CollectionUpdateAction.java:56)
    	at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
    	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
    	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:144)
    	at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
    	at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
    	at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
    	at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
    	at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
    	at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:54)
    	at gmo.basketballtrainer.utils.HibernateUtil.merge(HibernateUtil.java:27)
    	at gmo.basketballtrainer.frame.ManagementFrame.jMenuItemSaveActionPerformed(ManagementFrame.java:1220)
    	at gmo.basketballtrainer.frame.ManagementFrame.access$3000(ManagementFrame.java:37)
    	at gmo.basketballtrainer.frame.ManagementFrame$30.actionPerformed(ManagementFrame.java:921)
    	at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
    	at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
    	at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    	at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    	at javax.swing.AbstractButton.doClick(AbstractButton.java:376)
    	at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:833)
    	at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:877)
    	at java.awt.Component.processMouseEvent(Component.java:6505)
    	at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
    	at java.awt.Component.processEvent(Component.java:6270)
    	at java.awt.Container.processEvent(Container.java:2229)
    	at java.awt.Component.dispatchEventImpl(Component.java:4861)
    	at java.awt.Container.dispatchEventImpl(Container.java:2287)
    	at java.awt.Component.dispatchEvent(Component.java:4687)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
    	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
    	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
    	at java.awt.Container.dispatchEventImpl(Container.java:2273)
    	at java.awt.Window.dispatchEventImpl(Window.java:2719)
    	at java.awt.Component.dispatchEvent(Component.java:4687)
    	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:703)
    	at java.awt.EventQueue.access$000(EventQueue.java:102)
    	at java.awt.EventQueue$3.run(EventQueue.java:662)
    	at java.awt.EventQueue$3.run(EventQueue.java:660)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
    	at java.awt.EventQueue$4.run(EventQueue.java:676)
    	at java.awt.EventQueue$4.run(EventQueue.java:674)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    	at java.awt.EventQueue.dispatchEvent(EventQueue.java:673)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
    	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
    	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
    	at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)
    Caused by: java.sql.SQLSyntaxErrorException: La table/vue 'MYTREENODE' n'existe pas.
    	at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source)
    	at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
    	at org.apache.derby.client.am.Connection.prepareStatement(Unknown Source)
    	at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:505)
    	at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:94)
    	at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:87)
    	at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:222)
    	at org.hibernate.persister.collection.AbstractCollectionPersister.insertRows(AbstractCollectionPersister.java:1341)
    	... 52 more
    Caused by: org.apache.derby.client.am.SqlException: La table/vue 'MYTREENODE' n'existe pas.
    	at org.apache.derby.client.am.Statement.completeSqlca(Unknown Source)
    	at org.apache.derby.client.net.NetStatementReply.parsePrepareError(Unknown Source)
    	at org.apache.derby.client.net.NetStatementReply.parsePRPSQLSTTreply(Unknown Source)
    	at org.apache.derby.client.net.NetStatementReply.readPrepareDescribeOutput(Unknown Source)
    	at org.apache.derby.client.net.StatementReply.readPrepareDescribeOutput(Unknown Source)
    	at org.apache.derby.client.net.NetStatement.readPrepareDescribeOutput_(Unknown Source)
    	at org.apache.derby.client.am.Statement.readPrepareDescribeOutput(Unknown Source)
    	at org.apache.derby.client.am.PreparedStatement.readPrepareDescribeInputOutput(Unknown Source)
    	at org.apache.derby.client.am.PreparedStatement.flowPrepareDescribeInputOutput(Unknown Source)
    	at org.apache.derby.client.am.PreparedStatement.prepare(Unknown Source)
    	at org.apache.derby.client.am.Connection.prepareStatementX(Unknown Source)
    	... 58 more

    Merci de votre aide.

  2. #2
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Par défaut
    Bonsoir,

    J'ai pas lu les codes mais regarde bien l'erreur:
    Caused by: org.apache.derby.client.am.SqlException: La table/vue 'MYTREENODE' n'existe pas.
    .

    A+.

  3. #3
    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
    Oui mais MyTreeNode est une classe abstraite et je veux une table par classe fille: Exercise et Theme.

    De plus j'ai créé les tables avec le code suivant et ça ne me la pas créée.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
            SchemaExport export = new SchemaExport(new Configuration().configure());
            export.create(true, true);
    Avec les annotations j'ai une table supplémentaire: HIBERNATE_UNIQUE_KEY. je ne vois pas à quoi elle sert.

  4. #4
    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 je suis repassé en annotation et ça fonctionne.

    Merci pour votre aide

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

Discussions similaires

  1. [Mapping] Mapping d'une classe implémentant TreeNode
    Par Spiritkill dans le forum Hibernate
    Réponses: 0
    Dernier message: 23/11/2012, 15h31
  2. Réponses: 5
    Dernier message: 29/12/2010, 15h13
  3. Réponses: 4
    Dernier message: 21/05/2010, 10h46
  4. Classe abstraite / MVC
    Par caramel dans le forum MVC
    Réponses: 5
    Dernier message: 01/04/2003, 09h27
  5. pb constructeurs classes dérivant classe abstraite
    Par Cornell dans le forum Langage
    Réponses: 2
    Dernier message: 10/02/2003, 19h02

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