-->
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.  [ 1 post ] 
Author Message
 Post subject: Date Comparision - Criteria Query
PostPosted: Wed Aug 18, 2004 10:18 am 
Newbie

Joined: Wed Aug 18, 2004 9:51 am
Posts: 2
Hibernate version:2.1.5

Mapping documents:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping package="com.usco_kn">
<class name="UeiInstance" table="UEI_INSTANCE">
<id
column="UEI"
name="Uei"
type="string"
>
<generator class="vm" />
</id>
<property
column="CREATE_STAMP"
length="7"
name="CreateStamp"
not-null="true"
type="date"
/>
<property
column="PROCESS_INSTANCE_ID"
length="32"
name="ProcessInstanceId"
not-null="true"
type="string"
/>
</class>

<query name="com.usco_kn.allUei">
from com.usco_kn.UeiInstance as uei
</query>

</hibernate-mapping>



Code between sessionFactory.openSession() and session.close():

try {
String startDateString = "2004-08-03 00:00:00";
String endDateString = "2004-08-17 23:59:59";
SimpleDateFormat formatter =
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date sd = null;
Date ed = null;
try {
sd = formatter.parse(startDateString);
ed = formatter.parse(endDateString);
} catch (ParseException e) {
e.printStackTrace();
}

List ueis = session.createCriteria(UeiInstance.class)
.add( Expression.ge("CreateStamp", sd))
.add( Expression.le("CreateStamp", ed))
.addOrder( Order.asc("CreateStamp")).list();

for (ListIterator iter = ueis.listIterator() ;iter.hasNext() ; ) {
UeiInstance aUei = (UeiInstance)iter.next();
System.out.println("Uei: " + aUei.getUei());
System.out.println("Date: " + aUei.getCreateStamp());
}

} finally {
// No matter what, close the session
session.close();
}
}
}

Full stack trace of any exception that occurs:

No Exceptions

Name and version of the database you are using:
Oracle 9i (9.2.0.4)

Debug level Hibernate log excerpt:


Hi,
I'm new to Hibernate and I'm trying to use the Criteria object to create my query. I want a list of UEIs (name of a column in the database) between two given dates (inclusive of both the dates)... In my eg. I gave start date as -> 2004-08-03 & end date as -> 2004-08-17, but it is displaying records only till 2004-08-16. I do see in the database there are records for the date "2004-08-17". I even tried using the "between" method, it also displays the same...

here is the output of my test program...

Uei: SOLifeCycle.884130613.0667.1315205
Date: 2004-08-03
Uei: SOLifeCycle.969124536.0752.LSP0035993
Date: 2004-08-03
Uei: SOLifeCycle.810009092.0902.0080784403
Date: 2004-08-12
Uei: SOLifeCycle.969124536.0752.9002115S1
Date: 2004-08-13
Uei: SOLifeCycle.969124536.0752.RMT0310_OUT1
Date: 2004-08-14
Uei: SOLifeCycle.969124536.0752.RMT0310_OUT3
Date: 2004-08-16
Uei: SOLifeCycle.884130613.0667.149824-61049
Date: 2004-08-16
Uei: SOLifeCycle.884130613.0667.149825-61050

Can anyone let me know.. why the dates for.. 2004-08-17 are not being displayed? Please advice...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.