-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: how to use date in the where clause [easy right? :( ]
PostPosted: Sun Dec 11, 2005 3:11 am 
Newbie

Joined: Fri Nov 18, 2005 11:57 am
Posts: 6
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:
<property name="publicationDate" type="date" column="publication_date" not-null="true" />

Here's the dom field
private java.util.Date publicationDate;


This works in mysql query browser:
SELECT * FROM articles a where a.publication_date <= '2005-12-11'

Thanks for the help and sorry for such a dumb question. I searched around and couldn't find it.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 11, 2005 6:13 am 
Newbie

Joined: Sat Nov 19, 2005 10:10 pm
Posts: 9
Try to use setParameter:
Code:
List articles = session.createQuery(
  "from stpns.dom.Article a where a.publicationDate <= :now ")
  .setParameter("now", new Date())
  .list();



Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.