0 Replies Latest reply on Oct 5, 2005 5:44 PM by The FreeCake

    Help for EJB Mapping

    The FreeCake Newbie

      hello,

      I have a problem to make this diagram mapping with hibernate annotation :

      [img]http://membres.lycos.fr/burnoutland/images/Diagrammedeclasses_gpw_minimal.png[/img]

      I think my relations are good... but the collection of tasks owned by a project is wrong !
      aproject.getTasks() return a collection of Task that contains several times the same task (if a task have two StateChange, the task is represented two times in the collection. etc.)

      If someone can tell me what is wrong with my code ...

      sorry for my bad english...

      @Entity
      @Table(name = "PROJET")
      public class Project implements java.io.Serializable {
       private static final long serialVersionUID = 1L;
      
       private int id;
      
       private String name = "";
      
       private Collection<Task> tasks = new ArrayList<Task>();
      
       //private Collection<EtatChange> etatsChange = new ArrayList<EtatChange>();
      
       public Project() {
      
       }
      
       public Project(String nom) {
       this.name = nom;
       }
      
       @Id(generate = GeneratorType.AUTO)
       public int getId() {
       return id;
       }
      
       public void setId(int id) {
       this.id = id;
       }
      
       public String getName() {
       return name;
       }
      
       public void setName(String nom) {
       this.name = nom;
       }
      
       @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "project")
       public Collection<Task> getTasks() {
       return tasks;
       }
      
       public void setTasks(Collection<Task> taches) {
       this.tasks = taches;
       }
      
      }
      @Entity
      @Table(name = "TACHE")
      public class Task implements java.io.Serializable {
       private static final long serialVersionUID = 1L;
      
       private int id;
      
       private String name;
      
       private Project project;
      
       private Collection<StateChange> statesChange = new ArrayList<StateChange>();
      
       public Task() {
       }
      
       @Id(generate = GeneratorType.AUTO)
       public int getId() {
       return id;
       }
      
       public void setId(int id) {
       this.id = id;
       }
      
       public String getName() {
       return name;
       }
      
       public void setName(String nom) {
       this.name = nom;
       }
      
       @ManyToOne
       public Project getProject() {
       return project;
       }
      
       public void setProject(Project projet) {
       this.project = projet;
       }
      
       @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "task")
       public Collection<StateChange> getStatesChange() {
       return statesChange;
       }
      
       public void setStatesChange(Collection<StateChange> statutsChange) {
       this.statesChange = statutsChange;
       }
      
      }
      @Entity
      @Table(name = "STATUTCHANGE")
      public class StateChange implements java.io.Serializable {
       private static final long serialVersionUID = 1L;
      
       private int id;
      
       private Date dateChange;
      
       private Task task;
      
       private State state;
      
       public StateChange() {
      
       }
      
       @Id(generate = GeneratorType.AUTO)
       public int getId() {
       return id;
       }
      
       public void setId(int id) {
       this.id = id;
       }
      
       public Date getDateChange() {
       return dateChange;
       }
      
       public void setDateChange(Date dateChange) {
       this.dateChange = dateChange;
       }
      
       @ManyToOne
       public State getState() {
       return state;
       }
      
       public void setState(State statutTache) {
       this.state = statutTache;
       }
      
       @ManyToOne
       public Task getTask() {
       return this.task;
       }
      
       public void setTask(Task tache) {
       this.task = tache;
       }
      }
      @Entity
      @Table(name = "STATUTTACHE")
      public class State implements java.io.Serializable {
       private static final long serialVersionUID = 1L;
      
       private int id;
      
       private String name;
      
       private boolean open;
      
       public State() {
       }
      
       public State(String nom) {
       this.setName(nom);
       }
      
       @Id(generate = GeneratorType.AUTO)
       public int getId() {
       return id;
       }
      
       public void setId(int id) {
       this.id = id;
       }
      
       public String getName() {
       return name;
       }
      
       public void setName(String nom) {
       this.name = nom;
       }
      
       public boolean isOpen() {
       return open;
       }
      
       public void setOpen(boolean open) {
       this.open = open;
       }
      
      }