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:
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:
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:
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:
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:
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.