title: Spring data join query not fetching results in junit
body: <p>I have an SpringBoot application in which I have defined an entity as given below</p>
  <pre><code>@Entity
  public class Organisation {
  
  @Id
  @GeneratedValue
  @JsonIgnore
  private Long id;
  
  private String entityId;
  private String type;
  
  @OneToMany(mappedBy = &quot;organisation&quot;, cascade = CascadeType.ALL, orphanRemoval = true)
  private Set&lt;OrganisationProperty&gt; properties = new HashSet&lt;&gt;();
  
  public Organisation(String entityId, String type,Set&lt;OrganisationProperty&gt; properties) {
      this.entityId = entityId;
      this.type = type;
      properties.forEach(p -&gt; {
          this.properties.add(new OrganisationProperty(p.getPropName(), p.getPropValue()));
      });
  }
  </code></pre>
  <p>In my service class I have a function to delete the properties</p>
  <pre><code>public void editOrgType(String orgTypeName, List&lt;OrgHierarchyEditProperty&gt; editProperties) {
  Set&lt;OrganisationProperty&gt; orgPropertiesToDelete = organisationPropertyRepository
                      .getOrganisationPropertyByTypeAndPropName(orgTypeName, editProperty.getOldPropName());
  organisationPropertyRepository.deleteAll(orgPropertiesToDelete);
  </code></pre>
  <p>This function to fetch is defined in the repository class</p>
  <pre><code>@Query(&quot;select p from Organisation o join OrganisationProperty p on o.id = p.organisation.id &quot;
          + &quot;where o.type = ?1 and p.propName = ?2&quot;)
  public Set&lt;OrganisationProperty&gt; getOrganisationPropertyByTypeAndPropName(String type, String propName);
  </code></pre>
  <p>I am testing the same logic through a junit test case</p>
  <pre><code>@Before
  public void setup() {
      Set&lt;OrganisationProperty&gt; circProperties = new HashSet&lt;&gt;();
      OrganisationProperty circProp = new OrganisationProperty(&quot;p&quot;, &quot;v&quot;);
      circProperties.add(circProp);
      Organisation circle = new Organisation(&quot;circle1&quot;, &quot;circle&quot;, circProperties);
      circProp.setOrganisation(circle);
      circle = organisationRepository.save(circle);
  }
  
  @Test
  public void editOrgTypeAddDeleteTest() {
      List&lt;OrgHierarchyEditProperty&gt; editProperties = new ArrayList&lt;&gt;();
      OrgHierarchyEditProperty delProp = new OrgHierarchyEditProperty();
      delProp.setEditMode(Mode.DELETE);
      delProp.setOldPropName(&quot;p&quot;);
      editProperties.add(delProp);
      organisationService.editOrgType(&quot;circle&quot;, editProperties);
      Organisation circle = organisationRepository.findByEntityId(&quot;circle1&quot;).get();
      boolean deleted = circle.getProperties().stream().anyMatch(p -&gt; p.getPropName().equals(&quot;p&quot;));
      assertFalse(deleted);
  }
  </code></pre>
  <p>When I call the service through controller the logic works fine and the properties get deleted. But from the junit test case the function organisationPropertyRepository.getOrganisationPropertyByTypeAndPropName does not return anything and so the properties to delete &quot;p&quot; is never fetched and deleted. If I do a debug and call organisationPropertyRepository.findAll() inside the service it gets the property &quot;p&quot; but somehow the join query is not working from inside the junit</p>