title: Options to return a custom complex object from a spring data jpa
body: <p>I'm trying to get the data from MSSQL database using below logic. Couldnt identify the option to prepare a single query (SQL or JPQL) to get the repository reponse as MyTestSTO.Can someone suggest me the options available to acheive this.</p>
  <p>Expected object Format :</p>
  <pre><code>{
          &quot;id&quot;: &quot;1&quot;,
          &quot;name&quot;: &quot;Test&quot;,
          &quot;CabInfo&quot;: {
            &quot;CabStatus&quot;: 0,
            &quot;CabStatusStr&quot;: &quot;Active&quot;,
            &quot;CabFunctionalArea&quot;: {
              &quot;FunctionalAreaId&quot;: 3
              },
            &quot;CabApplication&quot;: {
              &quot;ApplicationId&quot;: 333,
              &quot;ApplicationAcronym&quot;: &quot;OBM Router&quot;
            }
          }
        }
         
  
  
  
  And JPARepository Class  is :
  
  
  
  
  public interface FloorPlanRepositoryExt extends JpaRepository&lt;Sites, Long&gt; { 
    
    //Other APIs on Sites Table.
    Can we use multiple news in below query ?
    @Query(value = &quot;select new TestDTo(sp.id,sp.name,sp.cabStatus,sp.cabStatusStr, 
    sp.functionalArea,sp.applicationId,sp.ApplicationAcronym) from SpacePower sp where sp.roomId=:roomId)
    public List&lt;TestDTo&gt; getRoomSpacesCabByRoomId(@Param(&quot;roomId&quot;)Integer roomId);
    }
  </code></pre>
  <p>My custom DTO is below:</p>
  <pre><code>class TestDTo implements serializable{
    
    private String id;
    privateString name;
    private CabInfo cabInfo
    //Setters and getters and Constructor
    }
  
  
  
  
  
   class CabInfo{
    
    private String cabStatus;
    private String CabStatusStr;
    
    private CabFunctionalArea cabFunctionalArea;
    private CabApplication CabApplication;
    //Setters and getters and Constructor
    
    }
  </code></pre>