Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hi,
Hopefully you can help me with this nightmare!!!!
SQL Below does not return any records when hibernate executes, however if I execute sql in Toad it returns 4 Rows. Very strange. Please help, I need this fixed for a production reporting system.
Thank you.
Code:
HQL Code ->
DatabaseUtil.beginSession();
StringBuffer hql = new StringBuffer();
hql.append("select item.literature.model.category.title,sum(item.quantity) ");
hql.append("from DealerOrderItem as item ");
hql.append("where item.order.status='I' ");
if(!StringUtil.isEmpty(startDate))
hql.append("and item.updated >= :startDate ");
if(!StringUtil.isEmpty(endDate))
hql.append("and item.updated <= :endDate ");
//add group by and order by clause
hql.append("group by item.literature.model.category.title ");
hql.append("order by item.literature.model.category.title asc");
//create query
Query q= DatabaseUtil.createQuery(hql.toString());
//set query parameters
if(!StringUtil.isEmpty(startDate) && !StringUtil.isEmpty(endDate))
{
q.setString("startDate",startDate);
q.setString("endDate",endDate);
}
else
{
if(!StringUtil.isEmpty(startDate))
q.setString("startDate",startDate);
else if(!StringUtil.isEmpty(endDate))
q.setString("endDate",endDate);
}
//list result
results = q.list();
Hibernate version 2.1.8: Oracle 10gCode:
select category4_.title as x0_0_, sum(dealerorde0_.QUANITY) as x1_0_ from DLR_ORDER_ITEM dealerorde0_, DLR_ORDER dealerorde1_, LITERATURE_MASTER literature2_, ITEM_MASTER model3_, ITEM_CATEGORY category4_ where dealerorde0_.LIT_ID=literature2_.LIT_ID and literature2_.MODEL=model3_.MODEL and model3_.CATEGORY=category4_.CATEGORY and ((dealerorde1_.STATUS='I' and dealerorde0_.ORDER_ID=dealerorde1_.ORDER_ID)and(dealerorde0_.UPDATED<=? )) group by category4_.title order by category4_.title asc
Code:
19 Apr 2005 14:52:49,878 DEBUG SessionImpl.find:1537 - find: select item.literature.model.category.title,sum(item.quantity) from DealerOrderItem as item where item.order.status='I' and item.updated <= :endDate group by item.literature.model.category.title order by item.literature.model.category.title asc
19 Apr 2005 14:52:49,880 DEBUG QueryParameters.traceParameters:122 - named parameters: {endDate=21-APR-2005}
19 Apr 2005 14:52:49,881 DEBUG SessionImpl.flushEverything:2267 - flushing session
19 Apr 2005 14:52:49,883 DEBUG SessionImpl.flushEntities:2467 - Flushing entities and processing referenced collections
19 Apr 2005 14:52:49,884 DEBUG SessionImpl.flushCollections:2808 - Processing unreferenced collections
19 Apr 2005 14:52:49,886 DEBUG SessionImpl.flushCollections:2822 - Scheduling collection removes/(re)creates/updates
19 Apr 2005 14:52:49,888 DEBUG SessionImpl.flushEverything:2291 - Flushed: 0 insertions, 0 updates, 0 deletions to 0 objects
19 Apr 2005 14:52:49,889 DEBUG SessionImpl.flushEverything:2296 - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
19 Apr 2005 14:52:49,891 DEBUG SessionImpl.autoFlushIfRequired:1828 - Dont need to execute flush
19 Apr 2005 14:52:49,892 DEBUG QueryTranslator.logQuery:207 - HQL: select item.literature.model.category.title,sum(item.quantity) from com.crestec.factory.beans.DealerOrderItem as item where item.order.status='I' and item.updated <= :endDate group by item.literature.model.category.title order by item.literature.model.category.title asc
19 Apr 2005 14:52:49,894 DEBUG QueryTranslator.logQuery:208 - SQL: select category4_.title as x0_0_, sum(dealerorde0_.QUANITY) as x1_0_ from DLR_ORDER_ITEM dealerorde0_, DLR_ORDER dealerorde1_, LITERATURE_MASTER literature2_, ITEM_MASTER model3_, ITEM_CATEGORY category4_ where dealerorde0_.LIT_ID=literature2_.LIT_ID and literature2_.MODEL=model3_.MODEL and model3_.CATEGORY=category4_.CATEGORY and ((dealerorde1_.STATUS='I' and dealerorde0_.ORDER_ID=dealerorde1_.ORDER_ID)and(dealerorde0_.UPDATED<=? )) group by category4_.title order by category4_.title asc
19 Apr 2005 14:52:49,895 DEBUG BatcherImpl.logOpenPreparedStatement:204 - about to open: 0 open PreparedStatements, 0 open ResultSets
19 Apr 2005 14:52:49,897 DEBUG BatcherImpl.getPreparedStatement:253 - preparing statement
19 Apr 2005 14:52:49,903 DEBUG Loader.doQuery:281 - processing result set
19 Apr 2005 14:52:49,904 DEBUG Loader.doQuery:298 - done processing result set (0 rows)
19 Apr 2005 14:52:49,906 DEBUG BatcherImpl.logClosePreparedStatement:211 - done closing: 0 open PreparedStatements, 0 open ResultSets
19 Apr 2005 14:52:49,908 DEBUG BatcherImpl.closePreparedStatement:275 - closing statement: