-->
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: Criteria year
PostPosted: Mon Feb 06, 2006 4:22 am 
Newbie

Joined: Tue Nov 23, 2004 11:07 am
Posts: 7
Location: Switzerland
Bonjour,

J'aimerais utiliser l'année d'une date comme critère dans hibernate depuis un object Calendar. J'essaye le code suivant sans succès:
Code:

Criteria ctr = session.createCriteria(MandatDTO.class);
// year
if (dto.getDelayYear() != 0) { ctr.add(Expression.eq("year(dateMandat)", new integer(dto.getDelayYear()))); }


Le système me retourne cette erreur:

Code:

net.sf.hibernate.QueryException: could not resolve property: year(dateMandat) of: ch.ejpd.mantra.dto.MandatDTO


Avez-vous une idée de comment le faire?

Merci


Top
 Profile  
 
 Post subject: Affichage de l'année
PostPosted: Thu Feb 09, 2006 10:23 am 
Beginner
Beginner

Joined: Fri May 13, 2005 9:39 am
Posts: 21
Pour avoir récemment utilisé une fonction stockée et mappée le résultat, je pense que vous pourriez créer un champ year dans votre classe, qui serait de type formula.

un peu comme ceci:
Code:
<property name="myYear" formula="EXTRACT(Year from maColonne)"  type="Integer"/>


A partir de ce mapping, vous pourrez ajouter le critère:
Code:
ctr.add(Expression.eq("myYear", new integer(dto.getDelayYear());


Cela devrait gazer.

Nota: La fonction SQL Extract ne fonctionne peut-être que sur Oracle, il faut prendre l'équivalent dans votre SGBD.


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.