I am currently looking to display data in a DataTable from view by PostgeSQL.
I have created an Entity class for the view and a Repository that extends DataTablesRepository, just like a normal table.
The standard findAll(dataTablesInput) retrieves the data successfully, but if I give it an additional specification, I cannot retrieve the data.
Entity
@Entity
@Data
@Immutable
@Table(name="table_view")
public class TableView {
@Id
@Column(name="id")
private int id;
@Column(name="event_time")
private Timestamp eventTime;
//other columns
…
}
Repository
@Repository
public interface TableViewRepository extends DataTablesRepository<TableView, Integer>{
}
Service
DataTablesOutput<TableView> dataList = new DataTablesOutput<TableView>();
dataList = tableViewRepository.findAll(input, specification);`
This is the method that generates the specification which retrieves data within a specified time period.
public Specification<TableView> additionalSpecification(Timestamp dateFrom, Timestamp dateTo) throws Exception{
return new Specification<TableView>() {
@Override
public Predicate toPredicate(Root<TableView> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
return criteriaBuilder.between(root.get("eventTime"), dateFrom, dateTo);
}
};
}
DataTabelsOutput after execution is as follows
DataTablesOutput(draw=2, recordsTotal=11, recordsFiltered=0, data=[], searchPanes=null, error=null)
When the same code is executed for a regular table, the data is successfully retrieved.
Do I need to do anything special to use specification for view?
I am currently looking to display data in a DataTable from view by PostgeSQL. I have created an Entity class for the view and a Repository that extends DataTablesRepository, just like a normal table.
The standard findAll(dataTablesInput) retrieves the data successfully, but if I give it an additional specification, I cannot retrieve the data.
Entity
Repository
Service
This is the method that generates the specification which retrieves data within a specified time period.
DataTabelsOutput after execution is as follows
DataTablesOutput(draw=2, recordsTotal=11, recordsFiltered=0, data=[], searchPanes=null, error=null)
When the same code is executed for a regular table, the data is successfully retrieved. Do I need to do anything special to use specification for view?