-->
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: createCriteria problem for using date between clause
PostPosted: Mon May 14, 2007 9:58 am 
Newbie

Joined: Fri May 11, 2007 4:41 pm
Posts: 1
I have problem with execute createCriteria statement with add restriction.between date values.

When I execute the following code,

if (session != null) {
try {
results = session.createCriteria("polo.userprofile.Bill","bill").add(
Restrictions.eq("bill.userprofile.userid",userid)).addOrder(
Order.desc("orderDate")).list();
log.debug("find bills by contractorid, result size: "+ results.size()); ;

} catch (RuntimeException re) {
log.error("find bills by contractorid "+ userid+ "failed", re);
}
}


the createCriteria statement works fine, and I get the correcte contains in the results list. However, when I add one or more Restrictions in the above statement as the following,

if (session != null){
try{

results = session.createCriteria("polo.userprofile.Bill","bill").add(
Restrictions.eq("bill.userprofile.userid", contractorid)).add(
Restrictions.between("endDate", startdate, endingdate)).list();
//.add(Restrictions.ne("status", 'Expired'))
//.addOrder (Order.desc("endDate")).list();
log.debug("show find result, result size: "+ results.size());
if(results != null && !results.isEmpty()){
Iterator ibill = results.iterator();
while(ibill.hasNext()){
Bill bill =(Bill)ibill.next();
Set tcode = bill.getTranscodes();
Set transcode = new HashSet(0);
Iterator itran = tcode.iterator();
while(itran.hasNext()){
Transcode newtranscode = (Transcode)itran.next();
transcode.add(newtranscode);
}
bill.setTranscodes(transcode); expiringBills.add(bill);
}
log.debug("find by all successful, result size: "+ results.size());
}
}catch(RuntimeException re){
og.error("find all expiring bills fail.",re);
}
}

it dose not work approperiate, I get an empty list sothat the nullpoint exception occures at runtime.

the code that executes the above createCriteria statement is as the following:

Session session = HibernateUtil.currentSession();
Transaction trans=null;

try{
trans = session.beginTransaction();
List result = billLocal.findExpiringBills
(contractorid, startdate, enddate);
curPage = new Page(result, pageNumber, Max_PageSize);
if (curPage==null){
return null;
}
List orderlist= curPage.getList();
Iterator iorder = orderlist.iterator();
Set creditcard = new HashSet(0);
while(iorder.hasNext()){
Bill tmporder = (Bill)iorder.next(); creditcard = tmporder.getCreditcards();
tmporder.setCreditcards(creditcard);
orders.add(tmporder);
}
curPage.setList(orders);

}catch (Exception iae){
iae.printStackTrace();
}
trans.commit();
HibernateUtil.closeSession();


I am using hibernatetools 3.2.0beta8. , eclipse 3.2 , and mySQL server 5.0 for a web application. Could anyone help me to solve this problem?
Appreciate any help!

my mapping file is :
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated May 9, 2007 3:14:50 PM by Hibernate Tools 3.2.0.beta8 -->
<hibernate-mapping>
<class name="polo.userprofile.Bill" table="bill" catalog="ebidc">
<comment></comment>
<id name="idbill" type="long">
<column name="idbill" />
<generator class="native" />
</id>
<many-to-one name="planclassify" class="polo.userprofile.Planclassify" fetch="select">
<column name="planid" not-null="true">
<comment></comment>
</column>
</many-to-one>
<many-to-one name="userprofile" class="polo.userprofile.Userprofile" fetch="select">
<column name="contractorid" not-null="true">
<comment></comment>
</column>
</many-to-one>
<property name="chargedfee" type="float">
<column name="chargedfee" precision="12" scale="0" not-null="true">
<comment></comment>
</column>
</property>
<property name="payment" type="java.lang.Float">
<column name="payment" precision="12" scale="0">
<comment></comment>
</column>
</property>
<property name="paymentDate" type="java.sql.Date">
<column name="paymentDate" length="10">
<comment></comment>
</column>
</property>
<property name="street" type="string">
<column name="street" length="45" not-null="true">
<comment></comment>
</column>
</property>
<property name="city" type="string">
<column name="city" length="30" not-null="true">
<comment></comment>
</column>
</property>
<property name="phone" type="string">
<column name="phone" length="11" not-null="true">
<comment></comment>
</column>
</property>
<property name="province" type="string">
<column name="province" length="20" not-null="true">
<comment></comment>
</column>
</property>
<property name="postcode" type="string">
<column name="postcode" length="7" not-null="true">
<comment></comment>
</column>
</property>
<property name="balance" type="float">
<column name="balance" precision="12" scale="0" not-null="true">
<comment></comment>
</column>
</property>
<property name="orderDate" type="java.sql.Date">
<column name="orderDate" length="10" not-null="true">
<comment></comment>
</column>
</property>
<property name="endDate" type="java.sql.Date">
<column name="endDate" length="10" not-null="true">
<comment></comment>
</column>
</property>
<property name="status" type="string">
<column name="status" length="20" not-null="true">
<comment>values: processing, approve , expired and cancel. This field only can view and update by system admin</comment>
</column>
</property>
<set name="creditcards" inverse="true" cascade="all">
<key>
<column name="idbill" not-null="true" unique="true">
<comment></comment>
</column>
</key>
<one-to-many class="polo.userprofile.Creditcard" />
</set>
<set name="cancelOrders" inverse="true" cascade="all">
<key>
<column name="idbill" not-null="true">
<comment></comment>
</column>
</key>
<one-to-many class="polo.userprofile.CancelOrder" />
</set>
<set name="transcodes" inverse="true" cascade="all">
<key>
<column name="idbill" not-null="true">
<comment></comment>
</column>
</key>
<one-to-many class="polo.userprofile.Transcode" />
</set>
</class>
</hibernate-mapping>


Full stack trace of any exception that occurs:


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.