title: Spring JPA Many-to-Many relationship fail to fetch data
body: <p>I have been developing an app with Spring and I'm using JPA to handle the DB. I have two entities and they are as follows</p>
  
  <p><strong>Partner Entity</strong></p>
  
  <pre><code>@Entity
  public class Partner {
  
   @ManyToMany()
   private List&lt;Tenant&gt; tenants;
  
   public List&lt;Tenant&gt; getTenants() {
       return tenants;
   }
  
   public void setTenants(List&lt;Tenant&gt; tenants) {
       this.tenants = tenants;
   }
  
  }
  </code></pre>
  
  <p><strong>Tenant Entity</strong></p>
  
  <pre><code>@Entity
  public class Tenant {
  ...
  }
  </code></pre>
  
  <p>These two entities have been exposed by the <code>PartnerService</code> and <code>TenantService</code> services.</p>
  
  <p>In another service class I'm retrieving the partner from the <code>PartnerService</code> and when I call the <code>partner.getTenants()</code> it returns a list of 0 elements. But in the database that particular partner has 2 tenants. My service class is as follows</p>
  
  <pre><code>@Service
  public class DBOutboundInjector implements OutboundInjector {
  
   private final ApplicationContext context;
  
   @Autowired
   public DBOutboundInjector(ApplicationContext context) {
       this.context = context;
   }
  
   @Override
   @Transactional
   public boolean insertEntry(Long partnerId) {
  
      PartnerService partnerService = context.getBean(PartnerService.class);
  
              Partner partner = partnerService.getPartnerById(partnerId);
              List&lt;Tenant&gt; partnerTenants = partner.getTenants();
  ...
    }
  }
  </code></pre>