2 Replies Latest reply on Dec 5, 2006 9:04 AM by smix007

    mappedBy reference an unknown target entity property

    svanbegin01

      I would like to define a ManyToMany association between
      2 Entities A and C.
      As an additional property is required in the JoinTable, I tried
      to define 2 OneToMany associations involving a new entity B.

      Each time I deploy on jboss-4.0.5.GA, I get this error:
      org.hibernate.AnnotationException :
      mappedBy reference an unknown target entity property :
      com.acme.dev001.ejb.B.a in com.acme.dev001.ejb.A.bs

      What's wrong in the code that follows ?


      --------------- A -----------------------
      @Entity
      public class A implements java.io.Serializable {

      @Id
      private short aNo;

      @OneToMany(
      targetEntity = com.acme.dev001.ejb.B.class,
      cascade = CascadeType.ALL,
      fetch = FetchType.EAGER,
      mappedBy = "a"
      )
      private Collection< B> bs = new ArrayList< B>();

      --------------- B -----------------------
      @IdClass(com.acme.dev001.ejb.BKey.class)
      @Entity
      public class B implements java.io.Serializable {

      @Id
      @ManyToOne(targetEntity=com.acme.dev001.ejb.A.class)
      @JoinColumn(name="aNo", nullable=false, updatable=false, insertable=false)
      private A a;

      @Id
      @ManyToOne(targetEntity=com.acme.dev001.ejb.C.class)
      @JoinColumn(name="cNo", nullable=false, updatable=false, insertable=false)
      protected C c;

      --------------- C -----------------------
      @Entity
      public class C implements java.io.Serializable {

      @Id
      private short cNo;

      @OneToMany(
      targetEntity = com.acme.dev001.ejb.B.class,
      cascade = CascadeType.ALL,
      fetch = FetchType.EAGER,
      mappedBy = "c"
      )
      private Collection< B> bs = new HashSet< B>();
      --------------------------------------------

      Thanks,
      Serge

        • 1. Re: mappedBy reference an unknown target entity property
          svanbegin01

          This problem was solved by replacing @Id annotations in Entity B
          with @EmbeddedId and @Embeddable constructs

          • 2. Re: mappedBy reference an unknown target entity property
            smix007

            Hello,
            you use @idClass. Whereas in my code I use @Embeddable and @EmbeddedId I thus seek a solution with my problem of joint for the following code:

            @Embeddable
            public class TermProjPK implements Serializable {
            private String auiw;
            @Column(name = "AUIS", nullable = false)
            private String auis;

            public class TermProj implements Serializable {
            @EmbeddedId
             private TermProjPK termProjPK;
            //jointure avec la table TermSource
             @ManyToOne
             @JoinColumn (name = "AUIW")
             private TermSource auiw;
             public TermSource getAuiw() {
             return auiw;
             }
            
             public void setAuiw(TermSource auiw) {
             this.auiw = auiw;
             }
            
            
             //jointure avec la table SnomedInter
             @ManyToOne
             @JoinColumn (name = "AUIS")
             private SnomedInter auis;
             public SnomedInter getAuis() {
             return auis;
             }
            
             public void setAuis(SnomedInter auis) {
             this.auis = auis;
             }
            @Column(name = "MODIF")
             private String modif;
            
             @Column(name = "SRC", nullable = false)
             private String src;

            public class TermSource implements Serializable {
             @Id
             @Column(name = "AUIW", nullable = false)
             private String auiw;
            @OneToMany(mappedBy="AUIW")
             private Collection<TermProj> termProjs;
            
             public Collection<TermProj> getTermProjs() {
             return termProjs;
             }
            
             public void setTermProjs(Collection<TermProj> termProjs) {
             this.termProjs = termProjs;
             }

            public class SnomedInter implements Serializable {
            @Id
             @Column(name = "AUIS", nullable = false)
             private String auis;
            @OneToMany(mappedBy="AUIS")
             private Collection<TermProj> termProjs;
            
             public Collection<TermProj> getTermProjs() {
             return termProjs;
             }
            
             public void setTermProjs(Collection<TermProj> termProjs) {
             this.termProjs = termProjs;
             }

            I have the error message according to
            org.hibernate.AnnotationException: mappedBy reference an unknown property: ejb.entity.TermProj.AUIS in ejb.entity.SnomedInter.AUIS
            
            ,
            thank you in advance