Select max value of numeric CollectionOfElements with Hibernate

Consider a numeric CollectionOfElements held by a class Product such as:
@Entity(name="Product")public class Product {protected Set serialNumbers = new HashSet();@[email protected](name="product_serialnumbers")public Set getSerialNumbers() {  return serialNumbers;}public void setSerialNumbers(Set serialNumbers) {  this.serialNumbers = serialNumbers;}}
You can use a NamedQuery to determine the maximum SerialNumber held by any Product like this:
@Entity(name="Product")@NamedQueries ({    @NamedQuery(        name = "maxSerialNumber",        query = "select max(elements(p.serialNumbers)) as value from Product p"        )})public class Product {protected Set serialNumbers = new HashSet();@[email protected](name="product_serialnumbers")public Set getSerialNumbers() {  return serialNumbers;}public void setSerialNumbers(Set serialNumbers) {  this.serialNumbers = serialNumbers;}}
Share Comments