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:
|