1 Reply Latest reply on Mar 16, 2006 3:51 AM by Roberto Colmegna

    Many2Many problem

    Roberto Colmegna Newbie

      Hi,

      when I call and oABean.getBBeans(), on an ABean loaded from DB,
      I obtain a "null" Set [on DB exist a C-record which link loaded
      A-record with B-records]. Any Idea?

      package test.ejb.entity;

      import java.util.*;
      import javax.persistence.*;
      import javax.ejb.*;

      @Entity
      @Inheritance
      @Table(name="a")

      @NamedQuery(
      name="ABean.findAll",
      query="SELECT o FROM ABean o ORDER BY o.m_sInfo DESC"
      )

      public class ABean { //extends IdEntityBean {
      @Id
      @SequenceGenerator(name = "ASeq", sequenceName = "a_id_seq")
      @GeneratedValue(strategy = GenerationType.AUTO, generator = "ASeq")
      Integer id;
      public Integer getId() { return id;}

      @Column(name="info")
      String m_sInfo;

      @PrePersist
      public void setCreateInfo() {
      m_sInfo = "";
      }

      public String getInfo() { return m_sInfo;}
      public void setInfo(String info) { m_sInfo = info;}

      // table "c": link A<->B
      @ManyToMany
      @JoinTable(name="c",
      joinColumns={@JoinColumn(name="idA")},
      inverseJoinColumns={@JoinColumn(name="idB")}
      )
      Set BBeans;
      public Set getBBeans() { return BBeans;}
      public void setBBeans(Set BBeans) { this.BBeans=BBeans;}
      }


      TIA
      Roberto Colmegna