1 Reply Latest reply on Sep 16, 2005 1:12 PM by dsouza

    Recursive Many to Many Relationship

    alexian

      Hi! I'm developing in EJB3 but I have some problems to define a recursive many to many relationship. This is the code of the entity bean:

      package org.erion.ejb.test01.bean;
      
      import org.erion.ejb.test01.bean.Table02;
      
      import java.util.Collection;
      
      import java.io.Serializable;
      
      import javax.persistence.Entity;
      import javax.persistence.GeneratorType;
      import javax.persistence.Id;
      import javax.persistence.JoinColumn;
      import javax.persistence.ManyToOne;
      import javax.persistence.ManyToMany;
      import javax.persistence.FetchType;
      import javax.persistence.CascadeType;
      import javax.persistence.Column;
      import javax.persistence.Table;
      import javax.persistence.JoinTable;
      
      @Entity
      @Table(name = "Tabella01")
      public class Table01 implements Serializable {
       private int id;
       private String name;
       private Table02 type;
       protected Collection<Table01> overTables;
       protected Collection<Table01> subTables;
      
       public Table01(String n) {
       this.setName(n);
       }
      
       @Id(generate = GeneratorType.AUTO)
       @Column(name = "ID")
       public int getId() {
       return this.id;
       }
      
       public void setId(int id) {
       this.id = id;
       }
      
       @Column(name = "Nome")
       public String getName() {
       return this.name;
       }
      
       public void setName(String n) {
       this.name = n;
       }
      
      
       @ManyToOne
       @JoinColumn(name = "idTipo")
       public Table02 getType() {
       return this.type;
       }
      
       public void setType(Table02 t) {
       this.type = t;
       }
      
       @ManyToMany(
       cascade = {
       CascadeType.PERSIST,
       CascadeType.MERGE
       },
      
       fetch = FetchType.EAGER,
       mappedBy = "overTables"
       )
       public Collection<Table01> getSubTables() {
       return this.subTables;
       }
      
       public void setSubTables(Collection<Table01> st) {
       this.subTables = st;
       }
      
       @ManyToMany(
       cascade = {
       CascadeType.PERSIST,
       CascadeType.MERGE
       },
       fetch = FetchType.EAGER
       )
       @JoinTable(
       table = @Table(name = "GerarchiaTabelle01"),
       joinColumns = {@JoinColumn(name = "idTabella01")},
       inverseJoinColumns = {@JoinColumn(name = "idSottoTabella01")}
       )
       public Collection<Table01> getTables() {
       return this.overTables;
       }
      
       public void setTables(Collection<Table01> t) {
       this.overTables = t;
       }
      }
      


      I tried to deploy in JBoss 4.0.2 but it returned to me an error:

      14:57:23,837 ERROR [URLDeploymentScanner] Incomplete Deployment listing:
      
      --- MBeans waiting for other MBeans ---
      ObjectName: jboss.j2ee:service=EJB3,module=tablebeans.ejb3
       State: FAILED
       Reason: org.hibernate.AnnotationException: mappedBy reference an unknown property: org.erion.ejb.test01.bean.Table01.overTables
      
      --- MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM ---
      ObjectName: jboss.j2ee:service=EJB3,module=tablebeans.ejb3
       State: FAILED
       Reason: org.hibernate.AnnotationException: mappedBy reference an unknown property: org.erion.ejb.test01.bean.Table01.overTables
      


      What's wrong? I don't really understand because the property overTables is defined, but JBoss is not able to find it! Why?