I'm trying to make a work order system just for me to train. In work orders I can have several categories. And my doubt is when it is time to display, for example, a ranking of the most used categories for a period x using criteria of hibernate . Something that the result was organized like this:
Category A - 10 times
Category B - 8 times
Category C - 5 times
What can I use in this case?
Classes are briefly mapped so
ClassService
@SuppressWarnings("serial")
@Entity
@Table(name = "ordem_servico")
public class OrdemServico extends GenericModel {
@NotNull
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "data_os", nullable = false)
private Date dataOS;
@ManyToMany(cascade = { CascadeType.MERGE, CascadeType.REFRESH })
@JoinTable(name = "os_categoria", joinColumns = @JoinColumn(name = "id_os"),inverseJoinColumns = @JoinColumn(name = "id_categoria"))
private List<Categoria> categorias;
}
Class Category
@SuppressWarnings("serial")
@Entity
@Table(name = "categoria_os")
public class Categoria extends GenericModel {
@Column(name = "nome_cat", nullable = false, length = 40)
@NotBlank
private String nome;
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
}