Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
Query query = session.createQuery("from Purchase p where p.bought between :startDate and :endDate");
query.setParameter("startDate", someDate);
query.setParameter("endDate", anotherDate);
List<Purchase> purchases = query.list();
Using any ORM you will get a list for a Select request
Example with ApacheCayenne
list roles;
SelectQuery select_role = new SelectQuery(Role.class);
roles = Context.getContext().performQuery(select_role);
as a result in roles there will be a list
In Hibernate I think in the same way. However, dates are a little more complicated.
This is how the Cayenne proposes to work with dates
Calendar c = new GregorianCalendar();
c.set(c.get(Calendar.YEAR) - 100, 0, 1, 0, 0, 0);
Expression qualifier3 = Expression.fromString("artist.dateOfBirth < $date");
qualifier3 = qualifier3.expWithParameters(Collections.singletonMap("date", c.getTime()));
SelectQuery select3 = new SelectQuery(Painting.class, qualifier3);
List paintings3 = context.performQuery(select3);
There is a selection of paintings by those artists who were born more than 100 years ago
SELECT * FROM `buys` WHERE `date` BETWEEN '2000-01-01' AND '2000-01-31'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question