I have one ‘Log‘ entity which contains information about temperature.
I’m trying to build a report which have two fields only:
quantity : this field will tell how much my search should look
interval : minutes, hours, days, months, years (this field tells me how much is the interval of the search
This is my Log entity:
public class Log implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Integer id;
private Timestamp time;
private String value;
// getters and setters ...
So when the user inform like 1 minute I should look for the last minute (or 60 records at least).
Or if 1 month I should get all the data from the last month.
I’m trying something like this:
log.time < CURRENT_TIMESTAMP AND log.time > :param
But how can I specify to minutes, hours ? What I mean is how can be more specific in my query ?
If the time unit is “days”:
Keep your query as is, and bind
paramto the:paramrequest parameter.For other intervals, do the same, but with the appropriate Calendar field (HOUR_OF_DAY, MINUTE, etc.) instead of Calendar.DAY_OF_MONTH.