-->
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.  [ 2 posts ] 
Author Message
 Post subject: how to fix 'on' problem
PostPosted: Mon Sep 11, 2006 6:26 am 
Newbie

Joined: Mon Jul 24, 2006 4:01 am
Posts: 3
I have two table, "Plan" and "TJianjinDan" . and they are also have a column called "PlanCode". but "TJianjinDan" is independent of "Plan",because the column "planCode" of TJianjinDan just have the same content with the column "planCode " of "Plan".

I write native sql below:
select t.planCode,max(t.boatName),max(t.cargoName),max(t.cargoSpec),count(t.carCode),sum(t.jingZhong),+
max(t.faHuoDanWei),max(t.shouHuoDanWei) from Plan as m left join TjianjinDan as t on m.planCode=t.planCode where t.secondTime between '2006-8-10' and '2006-9-20' and lower(t.planCode) like '%%'
group by t.planCode

YE,I work right in DBMS SUCH AS MSSQL.

But, when I write sql with hibernate below:

query=getHibernateTemplate().getSessionFactory().
getCurrentSession().createQuery("select t.planCode,max(t.boatName),max(t.cargoName),max(t.cargoSpec),count(t.carCode),sum(t.jingZhong)," +
" max(t.faHuoDanWei),max(t.shouHuoDanWei) from MainPlan m left join TjianjinDan t on m.planCode=t.planCode " +
" where t.secondTime between :beginTime and :endTime and lower(t.planCode) like:planCode " +
" group by t.planCode");
query.setTimestamp("beginTime", begin);
query.setTimestamp("endTime", end);
query.setString("planCode","%%"+ planCode+"%%");


OK,It cannot work. hibernate throw error below:
unexpected token: on near line 1, column 206.

yes,hibernate cannot identify the token "on" .how to fix this probem.

thank you!
asper


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 11, 2006 8:36 am 
Senior
Senior

Joined: Wed Aug 17, 2005 12:56 pm
Posts: 136
Location: Erie, PA (USA)
You are confusing SQL & HQL. HQL does not support the specification of join condition (ON ...) -- the join condition is specified in the mapping.

Your choices are:
1. Get the mappings correct and then use HQL;
2. Use Hibernate's native SQL support.

Review the manual for more info.

_________________
---- Don't forget to rate! ----


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