date « Query « JPA Q&A





1. How to assign Date parameters to Hibernate query for current timezone?    stackoverflow.com

When you assign a date to a named SQL parameter Hibernate automatically converts it to GMT time. How do you make it use the current server timezone for all dates? Lets say ...

2. Using dates in the "where" clause of HQL query    stackoverflow.com

I am using the SQLite database and have the following persistent class (simplified):

public class Project
{
    public virtual int Id { get; set; }
    ...

3. How do I use the current date in an HQL query with an Oracle database?    stackoverflow.com

I'm trying to write this query using Hibernate 3 and Oracle 10.

from Alert alert
where alert.expiration > current_date()
order by alert.priority, alert.updated, alert.name
It's creating SQL like this -
Hibernate: select alert0_.ANNOUNCEMENTS_ID as ...

4. Format date in hql query    stackoverflow.com

i want to format date to string in hql select, for example i have purchasing data with transaction date in it:

class Purchase {

  private Date datePurchase

}
and i want to select ...

5. MySQL Hibernate sort on 2 columns    stackoverflow.com

I have a table as follows Table item {
ID - Primary Key
content - String
published_date - When the content was published
create_date - When this database entry was created
} Every hour ...

6. HQL Select using Date as criteria error    stackoverflow.com

In HQL, I am trying to use date as a criteria get some data but i am getting an error: Code:

Date DatePlaced=new Date();
        auction.setDatePlaced(DatePlaced);
  ...

7. With Hibernate/JPA query inHQL/JQL only how do I set where clause to last x days?    stackoverflow.com

I am looking for the HQL equivalent of converting x amounts days from current timestamp to a queriable value. So like this sudo-HQL : from Newspaper as newspaper where newspaper.published < ...

8. How to sort a query result by their date (Jpa, Java Collections)    stackoverflow.com

public List<Movie> findRange(int[] range) {
    CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
    cq.select(cq.from(Movie.class));
    Query q = em.createQuery(cq);
    q.setMaxResults(range[1] - range[0]);
   ...

9. JPQL Query Date with interval    stackoverflow.com

I am using JPA and JPQL. And I am new in this world;-) My Query is now giving me data between 2 dates.

Query query =em.createQuery("SELECT d FROM DTable d JOIN d.history p ...





10. How to query on a month for a date with Hibernate criteria    stackoverflow.com

I need to use criteria to query a database. The data I'm searching has a date, say 'startDate' and I have a month say 0 for January, I need to extract all ...

11. HQL query using a date column    stackoverflow.com

I am trying to create a query that will return a List of Person objects based on if the createDate field falls after a passed string that represents a date. My createDate ...

12. Giving criteria in hibernate query to get values having start date as previous month's date i.e current month minus 1    stackoverflow.com

Giving criteria in hibernate query to get values having start date as previous month's date i.e current month minus 1. I have a table in database that has a date field. I want ...

13. problem in date column with hibernate hql query    stackoverflow.com

i hav a hql query..it gets the data used between two dates..i wriiten a query like this
from com.cod.model.Billing where datecolumn between '2011-4-4' and '2011-4-20' but i didn't get any results from ...

14. how to find date difference result in minutes    stackoverflow.com

I have a date field in my table.Now i want to check if currentTime -DbDatetime > xminutes.How can i do it in sql hibernate

query = session.creatQuery(Select x from Xabc where :currentTime- ...

15. HQL date query question    stackoverflow.com

if I am expecting a Date object say for 2011-03-05 and I want to use HQL to pull everything in 2011-03, ignoring the day/05 something like where year(somecolumn) = year(datepassedin) and month(somecolumn) = ...

16. JPA add seconds to date in query    stackoverflow.com

I have a table called "Task" which has, among others, two columns:

  • Date_due: a TIMESTAMP date
  • Wait_in_seconds: a number (INT) of seconds
I want to add the Wait_in_seconds value to the date in ...





17. Query with date and timespan in Hibernate    stackoverflow.com

I want to use Hibernate to query with the condition like where A.beginTimestamp + A.timespan > current_timestamp(). The beginTimestamp is a timestamp column and A.timespan is the time span in seconds. How ...

18. HELP JPA QUERY COMPARE CURRENT DATE.    forums.netbeans.org

In SQL it is working SELECT * FROM TABLE WHERE enddate < current_date In JPA is not working SELECT t FROM TABLE t WHERE t.enddate < current_date WHYYYYYYYYYYYYYYYYYYY? Hope anyone can ...

19. writing a HQL query with date calculation    coderanch.com

The mySQL query below is what I want to write in HQL to obtain a list of all objects with the respective id's. The fields in the query; last_update_date is a date & interval is an integer specifying the number of days. select acct_id from profiles where sysdate() >= adddate(last_update_date, interval) Thanks in advance for any help in figuring this out. ...

20. How to add year in a given date using Hibernate Query    coderanch.com

Hi , Actually the below mentioned Hibernate Query is not working "select (bwSubMemberDE.registrationDateFrom + 60 YEARS) as REG from BwSubMemberDE as bwSubMemberDE" Its throwing exception for Bad Sql grammar. And I have one restriction that I can not use native sql query. [ April 05, 2008: Message edited by: Bear Bibeault ]

21. Using Hibernate to do Oracle query with to_date function    coderanch.com

Hi Paul, Thanks for the reply . . . Ok, I can execute my native SQL Query and get my results as an array of "generic" objects . . . but now I want to convert them to an array of objects my specific type of bean . . . I'm working on this . . . can you suggest an ...

22. Using SQL date() function in HQL Select    coderanch.com

Hello guys I am running into a problem using Hibernate, basically I need to translate the follow SQL (to HQL) SELECT count(*), status, date(eventDate) from call_detail where clientid = 32 and date(eventDate) GROUP BY status, date(eventDate) to HQL (which i am doing as follows) SELECT count(*), status, date(eventDate) from CallDetail where clientId = 32 and date(eventDate) GROUP BY status, date(eventDate) Now ...

23. Group By and Date Function Hibernate on MySql    coderanch.com

Please have a look at this My Sql table called ipdaily where column LAST_VISIT is a time stamp. "DOMAIN","YEAR","MONTH","DATE","IP","HITS","VOLUME","PAGES","LAST_VISIT" "0000003",2009,10,5,"195.4.144.33",3,6564,0,"2009-11-05 01:04:53" "0000003",2009,10,4,"195.4.146.83",1,2903,0,"2009-11-04 03:32:38" "0000003",2009,10,5,"217.7.132.23",48,2567136,48,"2009-11-05 03:55:56" "0000003",2009,10,4,"217.7.132.23",48,2567280,48,"2009-11-04 03:58:26" "0000003",2009,10,5,"62.245.220.140",331,591555,0,"2009-11-05 03:58:02" "0000003",2009,10,4,"62.245.220.140",489,881086,0,"2009-11-04 03:59:01" "0000003",2009,10,4,"62.245.220.151",67,123748,0,"2009-11-04 03:55:03" "0000003",2009,10,5,"62.245.220.151",62,112411,0,"2009-11-05 03:55:02" "0000003",2009,10,4,"62.245.220.152",104,219344,1,"2009-11-04 03:55:38" "0000003",2009,10,5,"62.245.220.152",89,305378,5,"2009-11-05 03:55:38" "0000003",2009,10,4,"78.34.153.15",14,98200,3,"2009-11-04 00:13:27" "0000003",2009,10,5,"79.240.82.102",1,2418,0,"2009-11-05 00:55:56" "0000003",2009,10,5,"80.120.228.147",8,62415,4,"2009-11-05 01:19:26" "0000003",2009,10,5,"80.187.101.147",1,2418,0,"2009-11-05 00:56:42" "0000003",2009,10,5,"84.150.163.243",2,2253,0,"2009-11-05 00:33:04" "0000003",2009,10,4,"84.153.203.96",37,4099082,37,"2009-11-04 03:05:27" "0000003",2009,10,4,"87.152.179.204",2,41651,1,"2009-11-04 00:38:06" "0000003",2009,10,5,"88.79.112.190",6,45840,1,"2009-11-05 00:57:18" "0000003",2009,10,5,"92.75.14.174",15,214426,8,"2009-11-05 02:19:17" I want to achieve ...

24. Hibernate Select - Criteria with a Date    coderanch.com

Hibernate appears to be using a 'fasttime' value?? for my date in its WHERE clause and doesn't return rows that it should from the database: Here's a 50K foot view of my Doman and DAO objects along with the SQL output. I'm using annotations for hibernate and have set the temporal type for my date objects to DATE (I've tried all ...

25. Need help with reporting query for dates - please help    forum.hibernate.org

Hi, I need to write a report query for dates. Unfortunately, the group by clauses are not in the database - they are dynamic and not part of a table or anything like that. I need to group like this: 1) today 2) yesturday 3) last 3 days 4) last 7 days 5) last 30 days 6) last 90 days The ...

26. java.sql.Date Required in Native Query    forum.hibernate.org

@PersistenceContext HibernateEntityManager em; String sql="SELECT * FROM TABLE1 WHERE DATE_CHANGED >= :changeDate"; public List getRecordsChanged() { Date date = DateUtils.addMonths(new Date(), -1); return em.createNativeQuery(sql, Table1.class) .setParameter("changeDate", date) .getResultList(); }

27. java.util.Date and query criteria    forum.hibernate.org

I have a MySQL table with a column type Date. In my hibernate mapping file I have mapped this column to java.util.Date. Now, while trying to retrieve results using criteria api based on date equality, I do not get any results if I set the Date using new Date(). If I normalize the date by setting hours, minutes and seconds to ...

28. how to Using SQL date() function in HQL group by ?    forum.hibernate.org

Hello guys I am running into a problem, basically I need to translate the follow SQL (to HQL) Code: SELECT count(*), status, date(eventDate) from call_detail where clientid = 32 and date(eventDate) GROUP BY status, date(eventDate) to HQL (which i am doing as follows) Code: SELECT count(*), status, date(eventDate) from CallDetail where clientId = 32 and date(eventDate) GROUP BY status, date(eventDate) ...

29. SOLVED: Miss on Query Cache with Date Parameter    forum.hibernate.org

I'm caching a few different queries. I have one that always misses. It has a Date parameter but I zero out the time. I need some help investigating the problem. Here is the portion of the log output: DEBUG org.hibernate.cache.EhCache - Element for sql: select ... where this_.RPT_ID=? and (sq2_.END_DT>? or sq2_.END_DT is null) and sq2_.RPT_FLG=?; parameters: 1234, Fri Jun 18 ...

30. Miss on Query Cache with Date Parameter    forum.hibernate.org

31. Query cache intentionally left out of date    forum.hibernate.org

So, I've got a huge stored procedure. Takes 20+ seconds to pull all sorts of counts about messages coming into the database that are all displayed on a single dashboard page. Obviously this time delay is unacceptable for the users. I would love to use the hibernate query cache, but since messages are constantly coming in it would be constantly invalidating ...

32. Comparing the Date of a DateTime property, like MySQL DATE()    forum.hibernate.org

public List findByCreationDateTime(DateTime fromDateTime, DateTime toDateTime) { Criteria criteria = getSession().createCriteria(MailAddress.class); // TODO how to compare between the date only and ignore the time ? criteria.add(Restrictions.between("creationDateTime", fromDateTime.toDate(), toDateTime.toDate())); criteria.addOrder(Order.asc("firstname")).addOrder(Order.asc("lastname")).addOrder(Order.asc("email")); ...

34. Question: "group by date"    forum.hibernate.org

35. Group by and Date    forum.hibernate.org

36. Question about a date query    forum.hibernate.org

The thing is, I have to ignore the year, because it's the full birthday in the database. So that's why I'm using all the weird dateadds and datediff. I'm trying to get all the dates where their birthday (ignoring the year) is today. Which is hard to do when you try to take leap years and whatnot into account.

37. Query by Date Object    forum.hibernate.org

38. Probelam with date parameter in query    forum.hibernate.org

Hello, i have a problem with a query like this from doc in class model.Document where doc.fecha = :fecha and i set a query like this Query q= session.getNamedQuery(..... q.setDate("fecha",fecha) Where fecha is 14/01/2004 and in the dataBase the column that map to this propties has the same value The problem is that the query dosen't return any value, when it ...

39. unable to compare dates in MySQL query    forum.hibernate.org

I am unable to compare dates in MySQL queries. I'm trying to get all rows newer than a certain date by comparing the theDate column to a passed in parameter. I've tried explicitly stating the type in the mapping file with no luck. I was able to similarly compare integer fields, so I can't be too far off. I keep getting ...

40. Date query problem    forum.hibernate.org

Hi! I'm using MySQL 4.0.xx and have been trying to query the database for a dateinterval using all sorts of code... A search on this forum reveals that more people hva had problems with Date-querys and MySQL. Is this a known issue reported somewhere? Bug even? Heres the mapping -

41. How can I make Date comparison in HQL query    forum.hibernate.org

hi i am in difficulty of writing a correct Date comparison hql query. i have wrote the following query-- public Collection getPeriodicalApplicationList(Session session, Date fromDate, Date toDate) throws DaoException{ try{ String queryString = "from DeskProcessDto dto where dto.applicationDesk.applicationDateType between :param1 and :param2"; Query query = session.createQuery(queryString); query.setString("param1", DateFormatter.getInstance().format(fromDate, DateFormatter.getInstance().DATE_PATTERN_DD_MMM_YY)); query.setString("param2", DateFormatter.getInstance().format(toDate, DateFormatter.getInstance().DATE_PATTERN_DD_MMM_YY)); return query.list(); }catch(HibernateException _hbx){ _hbx.printStackTrace(); throw new DaoException(_hbx); } ...

42. Date problem in subqueries    forum.hibernate.org

Hi, I'm performing a subquery and I have a requirement saying that I'm only interested in data from a specific date. But Hibernate throws an exception. In the database the date format is datatype "date" (23-OCT-03) and in the Java classes the date has the datatype "Date". This is my query: Query q = session.createQuery("SELECT co.customerT.customerTPK.customerno, " + "co.customerorderTPK.customerorderno " + ...

43. Date Comparision - Criteria Query    forum.hibernate.org

Hibernate version:2.1.5 Mapping documents: from com.usco_kn.UeiInstance as uei Code between sessionFactory.openSession() and session.close(): try { String startDateString = ...

44. Date query using HQL    forum.hibernate.org

45. please help to write a query(distinct+date)    forum.hibernate.org

46. select query works with java.util.Date but not java.sql.Date    forum.hibernate.org

Beginner Joined: Tue Jul 20, 2004 1:53 am Posts: 43 Location: India Hibernate version:Hibernate 2.16 Database: Oracle 9i I have the following entity class : Code: package tavant.platform.persistence.hibernate.date; import java.sql.Date; public class Entity { private Long id; private Date someDate; public Entity() { ...

47. Getting date in simple sql queries    forum.hibernate.org

48. simply problem with queries on dates!! probably very simple!    forum.hibernate.org

i have a class of objects which have a java date object as on of thier properties. how would I create a HQL query which did something along these lines: "from photos where takendate >= upperbound and <= lowerbound" the question i guess is what type the upperbound and lowerbound should be. i tried creating java date objects and then using ...

49. query based on dates with Criteria    forum.hibernate.org

I was able to get it working with the HQL, and I was also able to get it working with Criterion by making my own Criterion / Expression classes like this: Code: import net.sf.hibernate.expression.AbstractCriterion; import net.sf.hibernate.engine.SessionFactoryImplementor; import net.sf.hibernate.engine.TypedValue; import net.sf.hibernate.HibernateException; import net.sf.hibernate.type.IntegerType; import net.sf.hibernate.util.StringHelper; import java.util.Map; public class DateMonthEqExpression extends AbstractCriterion { private final String propertyName; ...

50. Date query by using Buddhist Era(BE) fail    forum.hibernate.org

Hi I'm having problem with Hibernate about date query. I try to query a record and then try to re-query with the criteria by using the data found previously. But there's no result returned. I think the year return is not match with the regional setting in my machine, coz I'm using Buddhist era (year 2005 = 2548 BE). The data ...

51. How to work with date in Named query    forum.hibernate.org

Hi, How can I do this SQL statement using a HQL (named query)? select * from mytable where date(mydate) > date(current date) and date(mydate) < date(current date) + 60 days; If I insert the date() I get an error on the named query when I start the server. Any idea? Thanks, Cristiane

52. how to use date in the where clause [easy right? :( ]    forum.hibernate.org

Hi, I want to limit the results where the article publicationDate field is past or present. This isn't working: Date now = new Date(); List articles = getHibernateTemplate().find("from stpns.dom.Article a where a.publicationDate <= '" + now.toString() + "'"); here's the sql: publication_date TIMESTAMP NOT NULL here's the mapping: Here's the dom field private java.util.Date publicationDate; ...

53. Problem with dates comparing in HQL query    forum.hibernate.org

Hi! I just started to study hibernate, so possibly my question rather silly. I have: (it's Date.toSring() output) start date: Sun Dec 19 00:00:00 MSK 2005 end date: Mon Dec 19 23:59:59 MSK 2005 Query String: select e.body, e.date, e.number from MessageEntry e where e.date <= :endDate AND e.date >= :startDate This query with dates does not match entries with date ...

54. HQL Date Query    forum.hibernate.org

55. How to query Dates with criteria?    forum.hibernate.org

Criteria criteria = session.createCriteria(Sale.class); if (startDate != null) { criteria.add(Expression.ge("date",startDate); } if (endDate != null) { criteria.add(Expression.le("date",endDate); } List results = criteria.list();

56. HQL Query for Date comparison    forum.hibernate.org

First of all, you should make clear whether you want the current date of your database engine or the one of your application server... If the value of your LST_MOD_DATE field is set by your application at the time Hibernate persist the entity, then you had better to build your query using the current time obtained from your application as well. ...

57. Adv. querying for dates    forum.hibernate.org

Hi there. I'll skip right to the problem. In my database I have a set of UserBeans in my database, all which has a born-date field. From this I want to get all of the users that have their birthday on a given date. Any clue upon how to do this with HQL or Criterias? I can easily check their age, ...

58. Cant select an aggregated date comparison using sysdate    forum.hibernate.org

org.hibernate.PropertyNotFoundException: no appropriate constructor in class: com.whatever.InventoryStatus at org.hibernate.util.ReflectHelper.getConstructor(ReflectHelper.java:230) at org.hibernate.hql.classic.QueryTranslatorImpl.renderSQL(QueryTranslatorImpl.java:586) at org.hibernate.hql.classic.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:180) at org.hibernate.hql.classic.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:152) at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:425) ...

59. Exact Date-based Paging    forum.hibernate.org

Because of the type of application, I can't use the standard "next 10 items" type of paging. In many applications, you can start at offset 10 for the second page. My situation is a bit different. I'm using Hibernate3 and various databases (Oracle9, MySQL 4.1, MS SQL server). First, I need to page based on a time interval (say 1 day). ...

60. URGENT: How to implement trigger like func? last_update_date    forum.hibernate.org

Hi, We need to add a column as LAST_UPDATE_DATE to all tables of an existing application. [developed using hibernate.] When Hibernate update any data it should also update the LAST_UPDATE_DATE=SYSDATE [ i.e. Database system date and not app server sysdate] So we cant use interceptor considering the extra call. is there any way to do it.... We can do it by ...

61. Dates and like clause    forum.hibernate.org

@SuppressWarnings("unchecked") public List findMoviesByDate(Date date, Integer noOfResults) { getHibernateTemplate().setMaxResults(noOfResults); DetachedCriteria criteria; criteria = DetachedCriteria.forClass(Movie.class); criteria.add(Restrictions.like("created", date)); criteria.addOrder(Property.forName("created").desc()); ...

62. Query for a Date range    forum.hibernate.org

63. query order by date desc    forum.hibernate.org

Hi, I have something like this: public class Usr { ... private List messageTopics = new ArrayList(); @OneToMany(mappedBy="usr") public List getMessageTopics() { return messageTopics; } ... I can retrieve the messageTopics using aUsr.getMessageTopics(), this returns a list as expected, now I'd like to get the messagesTopics according to a datefield in the object in a descending order, so that I can ...

64. Query: "Select from ... where date > given_date"    forum.hibernate.org

I got an object that contains a java.util.Date variable. This object is mapped via Hibernate to a mySQL database. The corresponding type of the variable is "datetime" in my mySQL database. Now i got the following dates in the object's table Date 1. Dec 2008 3. Nov 2008 25. Oct 2008 etc Intuitivly spoken what i want to do is a ...

65. Difficult Hibernate Query related to dates    forum.hibernate.org

Hello All, I need help with writing a query in Hibernate. The DDL for the table i am using is given below :- CREATE TABLE FRENCH_BATCH_DETAILS ( BATCH_ID NUMBER PK, BATCH_STARTDATE DATE NOT NULL, BATCH_ENDDATE DATE, BATCH_NAME NVARCHAR2(150), ) The above table stores Details of French Batches for a particular Institute. Sample Data is given below :- BATCH_ID BATCH_STARTDATE BATCH_ENDDATE BATCH_NAME ...

66. Hibernate Criteria- Projections for date_trunc?    forum.hibernate.org

67. Date trunc using Criteria Queries    forum.hibernate.org

Hi, I have tried to trunc date values in DB in a situation where user input date is matched against. But I am not able to do that. In my scenario I have a parent and a child and I have to match the date against the child object not the parent object. So I have created an alias to retrieve ...

68. How to find Date difference using HQL    forum.hibernate.org

Hi smannur, according to the HQL docs (see http://docs.jboss.org/hibernate/stable/core/reference/en/html/queryhql.html#queryhql-expressions) HQL supports a rich set of mathematical operators. At least the comparison operators work with date types. I don't know about the others. You should probably make sure what the exact results of your intermediate calculation steps are to find out where there is a problem. Comparing the result of a division ...