-->
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: [ hql ] date
PostPosted: Fri Jan 16, 2009 7:45 pm 
Beginner
Beginner

Joined: Fri Apr 23, 2004 6:39 pm
Posts: 23
Bonjour,

Je suis sur hibernate 3 et Oracle 9.

Je souhaite faire une requete hql sur une table, pour supprimer les lignes a une date J-6.

delete from MonObjet as m where m.maDate < current_date() - 6(day);

Mais cela ne marche pas.
Meme la requete suivante ne marche pas
"delete from MonObjet as m where m.maDate < " + new Date();



Merci


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 18, 2009 1:13 am 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
Quote:
delete from MonObjet as m where m.maDate < current_date() - 6(day);


Le signe "majeur que" est valide, mais on ne peut pas effectuer des operations d'addition/soustraction comme celle là sur dates.


Quote:
"delete from MonObjet as m where m.maDate < " + new Date();


ça te donnerait la répresentation String de la new Date(), laquel ne corresponde pas avec ce que la base de données subjacent est capabl de comprendre.

Le support de dates dépend très lourdement du type de base de donnés.
Mais tu peux utiliser une Criteria et manipuler la date à travers de Java

Code:
Calendar cal = Calendar.getInstance();
cal.set( year, month, day-6 );  -->tu  fais la soustraction ici



et après

Code:
Criteria criteria = session.createCriteria( Customer.class );
criteria.add( Restrictions.eq( "maData", cal) );
[/quote]

_________________
Gonzalo Díaz


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.