title: Why projection fields are not getting set while fetching data using projection by joining two unrelated entities in JPA?
body: <p>I am trying to get some specific column values using projection by joining two unrelated entities. But I am not getting any values.
  Repository code is:-</p>
  
  <pre><code>
      @Repository
      public interface PersonRepository extends CrudRepository&lt;Person, Long&gt; {
          @Query("SELECT p.id,p.firstName,p.lastName,a.city FROM Person p INNER JOIN Address a on p.id = a.personId")
          public List&lt;PersonAndAddressSummary&gt; findAllPersonSummary();
      }
  
  </code></pre>
  
  <p>Person class</p>
  
  <pre><code>@Entity
  public class Person {
      @Id
      private long id;
      private String firstName;
      private String lastName;
      private long phone;
  
      public long getId() {
          return id;
      }
  
      public void setId(long id) {
          this.id = id;
      }
  
      public String getFirstName() {
          return firstName;
      }
  
      public void setFirstName(String firstName) {
          this.firstName = firstName;
      }
  
      public String getLastName() {
          return lastName;
      }
  
      public void setLastName(String lastName) {
          this.lastName = lastName;
      }
  
      public long getPhone() {
          return phone;
      }
  
      public void setPhone(long phone) {
          this.phone = phone;
      }
  }
  </code></pre>
  
  <pre><code>Address class
  
      @Entity
      public class Address {
          @Id
          private int id;
          private String street;
          private String state;
          private int personId;
          private String country;
          private int houseNo;
          private String city;
  
          public int getId() {
              return id;
          }
  
          public void setId(int id) {
              this.id = id;
          }
  
          public String getStreet() {
              return street;
          }
  
          public void setStreet(String street) {
              this.street = street;
          }
  
          public String getState() {
              return state;
          }
  
          public void setState(String state) {
              this.state = state;
          }
  
          public int getPersonId() {
              return personId;
          }
  
          public void setPersonId(int personId) {
              this.personId = personId;
          }
  
          public String getCountry() {
              return country;
          }
  
          public void setCountry(String country) {
              this.country = country;
          }
  
          public int getHouseNo() {
              return houseNo;
          }
  
          public void setHouseNo(int houseNo) {
              this.houseNo = houseNo;
          }
  
          public String getCity() {
              return city;
          }
  
          public void setCity(String city) {
              this.city = city;
          }
      }
  </code></pre>
  
  <p>Projection interface</p>
  
  <pre><code>public interface PersonAndAddressSummary {
      public String getId();
  
      public String getFirstName();
  
      public String getLastName();
  
      public String getCity();
  }
  </code></pre>
  
  <p>After executing this Spring Boot application, the output I am getting is this.</p>
  
  <pre><code>[{"lastName":null,"firstName":null,"city":null,"id":null},{"lastName":null,"firstName":null,"city":null,"id":null},{"lastName":null,"firstName":null,"city":null,"id":null}]
  </code></pre>
  
  <p>Though there are records available which match perfectly for each Person in Address class(data available in person and address table). </p>