title: Get Max Value with Spring-JPA
body: <p>I want do query to my table with spring-JPA (I can't use @Query) for get the max register</p>
  
  <p>The query have any conditions:</p>
  
  <p>Initially my query get register where version is "x" and Validated is 1 and the process is a list.</p>
  
  <pre><code>version: "1A" 
  validated: 1 -&gt; It is always 1.   
  lista: ["process1","process2"] or with 3,4 process...
  
  myRepo.findByIdVersionCierreAndAndValidatedAndIdProcessIn(version, 1, lista);
  </code></pre>
  
  <p>But In my database I can be two registers:</p>
  
  <pre><code>1º
  
  version: "1A" 
  validated: 1 
  lista: ["process1","process2"]
  Exec: 1
  
  2º
  
  version: "1A" 
  validated: 0 
  lista: ["process1","process2"]
  Exec: 2
  </code></pre>
  
  <p>I need get the register with max Exec, because in my register 1º, validated is 1, <strong>BUT</strong> in my register 2, validated is 0 y con my old code, I get the register Exec1 - <code>"myRepo.findByIdVersionCierreAndAndValidatedAndIdProcessIn(version, 1, lista);"</code></p>
  
  <p>First I saw the post:
  <a href="https://stackoverflow.com/questions/22801219/spring-crud-repository-is-there-findonebymaxxyzcolumn">Spring CRUD repository: is there findOneByMaxXYZColumn()?</a></p>
  
  <p>So I modified my code:</p>
  
  <pre><code> myRepo.findFirstfindByIdVersionCierreAndAndValidatedOrderbyIdExecDescAndIdProcessIn(version, 1, lista);
  </code></pre>
  
  <p>Err:</p>
  
  <pre><code>Caused by: java.lang.IllegalArgumentException: Failed to create query method public abstract java.util.List es.repository.DataValidationRepository.findFirstfindByIdVersionCierreAndAndValidatedOrderbyIdExecDescAndIdProcessIn(java.lang.String,int,java.util.List)! No property orderbyIdExecDesc found for type int! Traversed path: TpValidaAuto.validated.
  </code></pre>
  
  <p>And</p>
  
  <pre><code> myRepo.findFirstfindByIdVersionCierreAndAndValidatedAndIdProcessInOrderbyIdExecDesc(version, 1, lista);
  </code></pre>
  
  <p>however I get a error when I run the SpringBoot:</p>
  
  <pre><code>   Caused by: org.springframework.data.mapping.PropertyReferenceException: No property inOrderbyIdExecDesc found for type String! Traversed path: TpValidaAuto.idProcess.
  </code></pre>
  
  <p>EDIT:</p>
  
  <pre><code>@Repository
  public interface DataValidationRepository extends CrudRepository&lt;TpValidaAuto, String&gt; {
      List&lt;TpValidaAuto&gt; findByIdVersionCierreAndAndValidatedAndIdProcessIn(String version, int validated, List&lt;String&gt; process);
  }
  </code></pre>
  
  <p>Entity:</p>
  
  <pre><code>@Entity
  @Table(name = "MyTable")
  @GETTER
  @SETTER
  public class TpValidaAuto {
  
      @Id
      @NotNull
      @Column(name = "ID")
      @JsonProperty("id")
      private String id;
  
      @NotNull
      @Column(name = "ID_FICHERO")
      @JsonProperty("file")
      private String idFile;
  
      @NotNull
      @Column(name = "ID_EJECUCION")
      @JsonProperty("exec")
      private int idExec;
  
      @NotNull
      @Column(name = "ID_PROCESO")
      @JsonProperty("process")
      private String idProcess;
  
      @Column(name = "ID_PERIODO")
      @JsonProperty("period")
      private String idPeriod;
  
      @Column(name = "FC_ULT_DATO")
      @JsonProperty("lastdatedata")
      private String lastDateData;
  
      @Column(name = "IND_INCLUIR_CIERRE")
      @JsonProperty("validated")
      @JsonFormat(shape = JsonFormat.Shape.BOOLEAN)
      private int validated;
  
      @Column(name = "ID_VERSION_CIERRE")
      @JsonProperty("lastdateclose")
      private String idVersionCierre;
  
      @NotNull
      @Column(name = "IND_DATOS_MODIF")
      @JsonProperty("modificated")
      private int modificated;
  
      @NotNull
      @Column(name = "FC_ALTA")
      @JsonProperty("createDate")
      private String createDate;
  
      @NotNull
      @Column(name = "USR_ALTA")
      @JsonProperty("createUser")
      private String createUser;
  
      @NotNull
      @Column(name = "FC_MODIFICACION")
      @JsonProperty("modificationDate")
      private String modificationDate;
  
      @NotNull
      @Column(name = "USR_MODIFICACION")
      @JsonProperty("modificationUser")
      private String modificationUser;
  
  @JsonGetter("validated")
  public boolean validated() {
      boolean result = true;
  
      if (this.validated == 0) {
          result = false;
      }
  
      return result;
  }
  
  @JsonSetter("validated")
  public void validated(boolean validated) {
      if (validated) {
          this.validated = 1;
      } else {
          this.validated = 0;
      }
  }
  </code></pre>