-->
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.  [ 11 posts ] 
Author Message
 Post subject: Probelam with date parameter in query
PostPosted: Fri Jan 16, 2004 10:13 am 
Newbie

Joined: Fri Jan 16, 2004 9:59 am
Posts: 18
Location: La Plata-Argentina / Luxembourg
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 must return at least 100 rows

Can anyone help me please !!!!!!!!!!1

PD: sorry about my english


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 16, 2004 10:14 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
How did you map this? Have you mapped the property as type="date" and are you passing an java.util.Data to the query? Please show your mapping and your actual code.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 16, 2004 10:17 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Note that in class is deprecated and not maintained.
Prefer
Code:
from model.Document as doc
where doc.fecha = :fecha

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Re: Probelam with date parameter in query
PostPosted: Fri Jan 16, 2004 10:21 am 
Newbie

Joined: Fri Jan 16, 2004 9:59 am
Posts: 18
Location: La Plata-Argentina / Luxembourg
this is my mapping

<class name="cl.sichile.documentos.model.Documento" table="DOC_DOC" >

<id name="id" column="id">
<generator class="native"/>
</id>


<!--
<id name="id" column="ID" unsaved-value="-1">
<generator class="native"/>

<generator class="sequence">
<param name="sequence">DOCUMENT_SEQUENCE</param>
</generator>
</id>
-->
<property name="numeroDocumento" column="DOC_NUM_DOC"/>
<property name="fecha" column="DOC_FEC_ING" type="date"/>
<property name="fechaControl" column="DOC_FECHA_CONTROL" type="date"/>

</class>

i try to set de type = date and didn't work

Another thing to try ??




surrizola wrote:
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 must return at least 100 rows

Can anyone help me please !!!!!!!!!!1

PD: sorry about my english


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 16, 2004 10:26 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
What is the database field type? Are you actually passing a java.util.Date as query parameter?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 16, 2004 10:28 am 
Newbie

Joined: Fri Jan 16, 2004 9:59 am
Posts: 18
Location: La Plata-Argentina / Luxembourg
the dataBase is SQLSERVER
the type of the field is dateTime
and i pass the parameter as java.util.Date


gloeglm wrote:
What is the database field type? Are you actually passing a java.util.Date as query parameter?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 16, 2004 11:25 am 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
surrizola wrote:
the dataBase is SQLSERVER
the type of the field is dateTime
and i pass the parameter as java.util.Date


Don't forget the database will do an *exact* match on the date/time.
Unfortunately, the DB and Java dates do not have the same precision - up to the second only for the DB date...

Have a look at the API JavaDoc for java.sql.Date - there is warning saying you have to set the milliseconds to 0 on your java.util.Date...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 16, 2004 11:35 am 
Newbie

Joined: Fri Jan 16, 2004 9:59 am
Posts: 18
Location: La Plata-Argentina / Luxembourg
the milliseconds in the parameter is setting to 0, but no in the data base,
i nid the minutes and seconds for other operation, but in the query i only need to compare by day month year

another chance ??


brenuart wrote:
surrizola wrote:
the dataBase is SQLSERVER
the type of the field is dateTime
and i pass the parameter as java.util.Date


Don't forget the database will do an *exact* match on the date/time.
Unfortunately, the DB and Java dates do not have the same precision - up to the second only for the DB date...

Have a look at the API JavaDoc for java.sql.Date - there is warning saying you have to set the milliseconds to 0 on your java.util.Date...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 16, 2004 11:39 am 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
surrizola wrote:
the milliseconds in the parameter is setting to 0, but no in the data base,
i nid the minutes and seconds for other operation, but in the query i only need to compare by day month year


Did you set hour, min & sec to 0 as well in the date you give as argument to the query ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 16, 2004 11:41 am 
Newbie

Joined: Fri Jan 16, 2004 9:59 am
Posts: 18
Location: La Plata-Argentina / Luxembourg
i set min & sec to 0 as well in the date i give as argument
but in the data base the min & sec is not 0




brenuart wrote:
surrizola wrote:
the milliseconds in the parameter is setting to 0, but no in the data base,
i nid the minutes and seconds for other operation, but in the query i only need to compare by day month year


Did you set hour, min & sec to 0 as well in the date you give as argument to the query ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 19, 2004 11:35 am 
Newbie

Joined: Fri Jan 16, 2004 9:59 am
Posts: 18
Location: La Plata-Argentina / Luxembourg
Can anyone help me with this problem please !!!!!!



surrizola wrote:
i set min & sec to 0 as well in the date i give as argument
but in the data base the min & sec is not 0




brenuart wrote:
surrizola wrote:
the milliseconds in the parameter is setting to 0, but no in the data base,
i nid the minutes and seconds for other operation, but in the query i only need to compare by day month year


Did you set hour, min & sec to 0 as well in the date you give as argument to the query ?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 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.