title: Finding the entity with the highest value in the embedded ID with a custom JPA query
body: <p>My entity has an composite id consisting of two properties, version and id. I want to find the entity with the highest version. In JPA limit is not possible, how can i restrict my current return to exactly one entity?</p>
  <pre><code>@Entity
  public class GatewayConfigEntity implements Serializable {
      @EmbeddedId
      private GatewayConfigEntityId gatewayConfigId;
  }
  
  @Embeddable
  public class GatewayConfigIdEntity implements Serializable {
      private int version;
      private UUID resourceId;
  }
  </code></pre>
  <pre><code>@Query(&quot;select config from GatewayConfigEntity config where config.deviceId=:deviceId order by config.gatewayConfigId.version desc&quot;)
  Set&lt;GatewayConfigEntity&gt; findLatestGatewayConfigForDevice(UUID deviceId);
  </code></pre>