Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Criteria sentence to find dates between today
PostPosted: Tue Jun 27, 2017 4:42 am 
Newbie

Joined: Tue Jun 27, 2017 4:34 am
Posts: 1
Hi everybody,

I need to find the result of two dates when today's date is between them.

Date fechahoy = new Date();
MClientesMTarifas mcmt = (MClientesMTarifas) getSession().createCriteria(MClientesMTarifas.class)
.add(Restrictions.eq("idcliente_cliente", idcliente))
.add(Restrictions.between(today, "fechainicio", "fechafin"))
.uniqueResult();

And I get this error:
GRAVE: org.hibernate.QueryException: could not resolve property: today of: org.dpsistem.spring.model.cliente.MClientesMTarifas

How can I get this result???

Thanks.


Top
 Profile  
 
 Post subject: Re: Criteria sentence to find dates between today
PostPosted: Tue Jun 27, 2017 5:20 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1226
The way you call the between method:

Code:
.add(Restrictions.between(today, "fechainicio", "fechafin"))


Does not match the way it was intended to be used. Follow the method signature and the match the parameters accordingly:

Code:
public static Criterion between(String propertyName, Object low, Object high) {
    return new BetweenExpression( propertyName, low, high );
}

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 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.