title: get max value of column using jpa criteria query
body: <p>I want to get the maximum value of column <code>relationId</code> from table <code>ElementRelationType</code>
  I have written code but its giving error</p>
  
  <pre><code>CriteriaBuilder cb1 = entityManager.getCriteriaBuilder();
  CriteriaQuery&lt;ElementRelationTypes&gt; cq1 = cb1.createQuery(ElementRelationTypes.class);
  Root&lt;ElementRelationTypes&gt; root = cq1.from(ElementRelationTypes.class);
  cq1.select(cb1.max(root.get("relationId")));
  </code></pre>
  
  <p>select and max both giving error
  how to get the integer max value</p>
  
  <pre><code>public class ElementRelationTypes {
  
  private RelationId relationLangPK=new RelationId(); 
  
  private Country country;
  private Status status;
  
  
  @EmbeddedId
  public RelationId getRelationLangPK() {
      return relationLangPK;
  }
  public void setRelationLangPK(RelationId relationLangPK) {
      this.relationLangPK = relationLangPK;
  }
  
  @Transient
  public Integer getRelationId() {
      return getRelationLangPK().getRelationId();
  }
  public void setRelationId(Integer relationId) {
      getRelationLangPK().setRelationId(relationId);
  }
  @Transient
  public Language getLanguage() {
      return getRelationLangPK().getLanguage();
  }
  public void setLanguageCode(Language language) {
      getRelationLangPK().setLanguage(language);
  }
  </code></pre>
  
  <p>and </p>
  
  <pre><code>public class RelationId implements Serializable {
  private static final long serialVersionUID = 1L;
  private Integer relationId;
  private Language language;
  
  @JoinColumn(name=PersistenseConstants.ELEMENT_RELATION_TYPE_COL_RELATION_ID)
  public Integer getRelationId() {
      return relationId;
  }
  
  public void setRelationId(Integer relationId) {
      this.relationId = relationId;
  }
  
  @OneToOne
  @JoinColumn(name=PersistenseConstants.LANGUAGE_ENTITY_COL_LANG_CODE)
  public Language getLanguage() {
      return language;
  }
  
  public void setLanguage(Language language) {
      this.language = language;
  }
  </code></pre>