title: Spring data JPA - The encapsulated expression is not a valid expressio
body: <p>While running the below query to get the latest message with the latest data  using the createdOn column
  i get the below error </p>
  
  <pre><code>select count(m) from MessageWorkFlowStatus  mwfs1 where mwfs1.createdOn =(select max(createdOn) from  MessageWorkFlowStatus mwfs2 where mwfs1.status= 'NEW' or mwfs1.status='IN PROGRESS') 
  </code></pre>
  
  <p>The encapsulated expression is not a valid expression</p>
  
  <p>Please let me know if i can run Query this way</p>