Я работаю над заменой ниже sql запроса и использую построитель критериев entitymanager. Я проверил другие блоги и документацию, но пока не увенчался успехом.
SELECT MIN (creation_date), MAX (creation_date), COUNT (*), источник FROM creation_tbl, где creation_date> =? Источник GROUP BY;
Мой текущий подход
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<Feed> criteriaQuery = criteriaBuilder.createQuery(Feed.class);
Root<Entity> root = criteriaQuery.from(Entity.class);
Expression es = root.<Date>get("creation_date");
criteriaQuery.where(criteriaBuilder.greaterThanOrEqualTo(es, dateSql));
criteriaQuery.multiselect(criteriaBuilder.greatest(root.<Date>get("creation_date")),
criteriaBuilder.least(root.<Date>get("creation_date")),
root.get("source"),
criteriaBuilder.count(root)).groupBy(root.get("source"));
Feed resultlist = entityManager.createQuery(criteriaQuery).getSingleResult();
System.out.println(resultlist);
Класс ETL
@Entity
@Table(name = "creation_tbl", schema = "test")
public class ETL implements Serializable {
private static final long serialVersionUID = 3940341617988134707L;
@Id
@GeneratedValue
private long id;
@Temporal(TemporalType.DATE)
@Column(name = "creation_date")
private Date creation_date;
@Column(name = "source")
private String source;
public ETL() {}
public Date getCreation_date() {
return creation_date;
}
public void setCreation_date(Date creation_date) {
this.creation_date = creation_date;
}
public String getSource() {
return source;
}
public void setSource(String source) {
this.source = source;
}
}
Класс фида
@Entity
public class Feed implements Serializable {
private static final long serialVersionUID = 3940341617988134707L;
@Id
@GeneratedValue
private long id;
@Temporal(TemporalType.DATE)
@Column(name = "max")
private Date creationDateMax;
@Temporal(TemporalType.DATE)
@Column(name = "min")
private Date creationDateMin;
@Column(name = "source")
private String source;
@Column(name = "count")
private Long count;
public Feed(long id, Date creationDateMax, Date creationDateMin, String source, Long count) {
this.id = id;
this.creationDateMax = creationDateMax;
this.creationDateMin = creationDateMin;
this.source = source;
this.count = count;
}
public Feed() {}
public String getSource() {
return source;
}
public void setSource(String source) {
this.source = source;
}
public Date getCreationDateMax() {
return creationDateMax;
}
public void setCreationDateMax(Date creationDateMax) {
this.creationDateMax = creationDateMax;
}
public Date getCreationDateMin() {
return creationDateMin;
}
public void setCreationDateMin(Date creationDateMin) {
this.creationDateMin = creationDateMin;
}
public Long getCount() {
return count;
}
public void setCount(Long count) {
this.count = count;
}
}
Сообщение об ошибке -
org.hibernate.PropertyNotFoundException: нет подходящего конструктора в классе: Feed