1 pièce(s) jointe(s)
Mapping d'une classe implémentant TreeNode
Bonjour,
J'ai un souci et je ne sais pas comment le résoudre.
Vous trouverez ci joint la structure de mes classes.
Un exercice ne peut pas avoir d'enfant et un thème peut avoir comme enfant soit un thème soit un exercice.
Je veux faire une table par classe fille de MyTreeNode.
Le merge et le refresh fonctionne très bien sans l'implémentation de l'interface TreeNode, mais si je l’implémente, j'ai cette erreur:
Code:
1 2
|
Caused by: org.hibernate.MappingException: Could not determine type for: javax.swing.tree.TreeNode, at table: Theme, for columns: [org.hibernate.mapping.Column(parent)] |
J'utilise hibernate par annotation, voici mes différentes classes:
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
|
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class MyTreeNode implements TreeNode{
protected int id;
protected MyTreeNode father;
@Id
@Column(name = "id")
@GeneratedValue(generator = "increment")
@GenericGenerator(name = "increment", strategy = "increment")
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@ManyToOne
@Cascade({CascadeType.MERGE,CascadeType.REFRESH})
public MyTreeNode getFather() {
return father;
}
public void setFather(MyTreeNode father) {
this.father = father;
}
} |
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 83 84 85 86 87 88 89 90 91 92
|
@Entity
@Table(name="Theme")
public class Theme extends MyTreeNode{
private String label;
private List<MyTreeNode> childList;
public Theme() {
label = "Thème";
childList = new ArrayList<MyTreeNode>();
}
public Theme(String label, List<MyTreeNode> childList, Theme father) {
super();
this.label = label;
this.childList = childList;
this.father = father;
}
@OneToMany(mappedBy = "father")
@Cascade({CascadeType.MERGE,CascadeType.REFRESH})
public List<MyTreeNode> getChildList() {
return childList;
}
public void setChildList(List<MyTreeNode> childList) {
this.childList = childList;
}
@Column(name = "label", nullable = true)
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public void setFather(Theme father) {
this.father = father;
}
@Override
public String toString() {
return label;
}
@SuppressWarnings("rawtypes")
@Override
public Enumeration children() {
return null;
}
@Override
public boolean getAllowsChildren() {
return true;
}
@Override
public TreeNode getChildAt(int childIndex) {
if(childList != null && childList.size() < childIndex){
return childList.get(childIndex);
}
return null;
}
@Override
public int getChildCount() {
if(childList != null){
return childList.size();
}
return 0;
}
@Override
public int getIndex(TreeNode node) {
if(childList != null){
return childList.indexOf(node);
}
return 0;
}
@Override
public TreeNode getParent() {
return 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
|
@Entity
public class Exercise extends MyTreeNode{
private String name;
private int nbOfDirectParticipant;
private int exerciseTime;
private String materials;
private List<Evolution> evolutionList;
private List<Training> trainingList;
public Exercise() {
name = "Exercice";
evolutionList = new ArrayList<Evolution>();
trainingList = new ArrayList<Training>();
}
public Exercise(String name, int nbOfDirectParticipant, Theme theme,
int exerciseTime, String materials, List<Evolution> evolutionList,
List<Training> trainingList) {
super();
this.name = name;
this.nbOfDirectParticipant = nbOfDirectParticipant;
this.exerciseTime = exerciseTime;
this.materials = materials;
this.evolutionList = evolutionList;
this.trainingList = trainingList;
}
@Column(name = "name", nullable = true)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Column(name = "nbOfDirectParticipant", nullable = true)
public int getNbOfDirectParticipant() {
return nbOfDirectParticipant;
}
public void setNbOfDirectParticipant(int nbOfDirectParticipant) {
this.nbOfDirectParticipant = nbOfDirectParticipant;
}
@Column(name = "exerciseTime", nullable = true)
public int getExerciseTime() {
return exerciseTime;
}
public void setExerciseTime(int exerciseTime) {
this.exerciseTime = exerciseTime;
}
@Column(name = "materials", nullable = true)
public String getMaterials() {
return materials;
}
public void setMaterials(String materials) {
this.materials = materials;
}
@OneToMany(mappedBy = "exercise")
@Cascade({CascadeType.MERGE,CascadeType.REFRESH})
public List<Evolution> getEvolutionList() {
return evolutionList;
}
public void setEvolutionList(List<Evolution> evolutionList) {
this.evolutionList = evolutionList;
}
@ManyToMany(mappedBy = "exerciseList", targetEntity = Training.class)
@Cascade({CascadeType.MERGE,CascadeType.REFRESH})
public List<Training> getTrainingList() {
return trainingList;
}
public void setTrainingList(List<Training> trainingList) {
this.trainingList = trainingList;
}
@Override
public String toString() {
return name;
}
@SuppressWarnings("rawtypes")
@Override
public Enumeration children() {
return null;
}
@Override
public boolean getAllowsChildren() {
return false;
}
@Override
public TreeNode getChildAt(int childIndex) {
return null;
}
@Override
public int getChildCount() {
return 0;
}
@Override
public int getIndex(TreeNode node) {
return 0;
}
@Override
public TreeNode getParent() {
return father;
}
@Override
public boolean isLeaf() {
return true;
}
} |
Merci d'avance pour votre aide.