-->
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.  [ 5 posts ] 
Author Message
 Post subject: Problem in Date comparision in JPQL
PostPosted: Mon Mar 08, 2010 12:43 pm 
Newbie

Joined: Mon Mar 08, 2010 12:05 pm
Posts: 3
Hello Everyone,

Is there any restrictions in JPQL for date equality comparision?

My requirement is to get all the student's information based on the admission date.
viz. If admissionDate is date-16.02.2010 time-15:03:08, then it should give me all the student's information who has admitted on date-"16.02.2010" time-"15:03:08"

In my orm.xml mapping file, i've the following JPQL query defined:
-----------clip---------
<orm:named-query name="valuesByKeys">
<orm:query>SELECT NEW studentValueDTO(x) FROM Student x WHERE x.admissionDate = :admissionDate</orm:query>
</orm:named-query>
-----------clap---------

"Student" is an ejb3.0 entity class which has a "admissionDate" field of type java.util.Date.
-----------clip---------
@Column(name = "ADMISSION_DATE")
@Temporal(TemporalType.DATE)
private java.util.Date admissionDate;
-----------clap---------

"StudentValueDTO" is a data tranferable object having just getters & setters methods.

I've following ejb 3.0 stateless session bean, which uses the orm.xml mapping file for making DB query:
----------------clip--------------
@PersistenceContext
private javax.persistence.EntityManager manager;

public List<StudentValueDTO> getStudentInfo (java.util.Date admissionDate){

javax.persistence.Query query = manager.createNamedQuery("valuesByKeys");
query.setParameter("admissionDate", admissionDate);
List<StudentValueDTO> result=(List<StudentValueDTO)query.getResultList();
manager.clear();
return result;
}
----------------clap--------------

I've written an ejb client (Out of container) to invoke the above stateless bean:
----------clip----------
java.util.Calendar cal = Calendar.getInstance();
cal.set(2010,01,16,15,03,8);

List<StudentValueDTO> studentList = remoteObject.getStudentInfo(cal.getTime());
----------clap----------

But when i print the contents of studentList, its always empty.
Also, i confirmed with the logs of hibernate, the query seems to be formed properly & binding too. But there are no result sets returned for this query.
I checked in my oracle DB, there are lots of data which matches this criteria i.e. having admissionDate as provided.

Require your kind help in this regard.
Thanks in advance.

_Sanjit


Top
 Profile  
 
 Post subject: Re: Problem in Date comparision in JPQL
PostPosted: Tue Mar 09, 2010 8:29 am 
Newbie

Joined: Mon Mar 08, 2010 12:05 pm
Posts: 3
Could anyone please help here?


Top
 Profile  
 
 Post subject: Re: Problem in Date comparision in JPQL
PostPosted: Tue Mar 09, 2010 10:18 am 
Regular
Regular

Joined: Thu May 07, 2009 5:56 am
Posts: 94
Location: Toulouse, France
hi,

try query.setParameter("admissionDate", admissionDate, TemporalType.DATE);

this should solve your issue.

_________________
everything should be made as simple as possible, but not simpler (AE)


Top
 Profile  
 
 Post subject: Re: Problem in Date comparision in JPQL
PostPosted: Tue Mar 09, 2010 8:45 pm 
Newbie

Joined: Mon Mar 08, 2010 12:05 pm
Posts: 3
Thanks for the reply hallmit.

But i already tried out this but it dint help :-(

_Sanjit


Top
 Profile  
 
 Post subject: Re: Problem in Date comparision in JPQL
PostPosted: Fri Feb 10, 2017 5:22 am 
Newbie

Joined: Fri Feb 10, 2017 5:18 am
Posts: 1
Late but to complete :

@Temporal(TemporalType.TIMESTAMP) in student entity


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