0
我有以下SQL查詢:如何爲這種情況創建hibernate映射?
SELECT CONNECTIONDATE AS UNLOAD,
SUBSTR(ROUTECODE,1,(LENGTH(ROUTECODE)-2)) AS ROUTE,
COUNT(SUBSTR(ROUTECODE,1,(LENGTH(ROUTECODE)-2))) AS FREQUENCY
FROM RouteTableSynonym RC1
WHERE RC1.ROUTECONNECTIONTYPE = 'INBOUND'
and RC1.CONNECTIONTIME >= TO_TIMESTAMP('<sdate>', 'DD-MM-YYYY HH24:MI:SS')
and RC1.CONNECTIONTIME <= TO_TIMESTAMP('<edate>', 'DD-MM-YYYY HH24:MI:SS')
and RC1.LOGISTICSPOINTID in (SELECT DISTINCT RCO1.LOGISTICSPOINTID
FROM RouteOrderTableSynonym RCO1
WHERE RCO1.NAMC = '<namc>')
GROUP BY CONNECTIONDATE, SUBSTR(ROUTECODE,1,(LENGTH(ROUTECODE)-2))
ORDER BY CONNECTIONDATE, ROUTE;
由指定的所有值「< VAR_NAME>」被替換與被查詢的值。我也有存儲此查詢的結果這個實體類:
import java.util.Date;
public class DD_BlackoutRouteFrequencies {
private Date rte_day;
private String route;
private int freq;
private int delayedFreq;
public Date getRte_day() {
return rte_day;
}
public void setRte_day(Date rte_day) {
this.rte_day = rte_day;
}
public String getRoute() {
return route;
}
public void setRoute(String route) {
this.route = route;
}
public int getFreq() {
return freq;
}
public void setFreq(int freq) {
this.freq = freq;
}
public int getDelayedFreq() {
return delayedFreq;
}
public void setDelayedFreq(int delayedFreq) {
this.delayedFreq = delayedFreq;
}
}
我執行這樣的查詢:
try{
SQLQuery sqlquery = session.createSQLQuery(query);
sqlquery.addEntity(DD_BlackoutRouteFrequencies.class);
results = sqlquery.list();
logger.debug(results.size());
System.out.println("Frequnecy Results size: "+results.size());
}catch(Exception e){
logger.error("Exception ", e);
throw new RuntimeException("SQL Exception getting Blackout Route Frequencies: "+ e.getMessage());
}
我遇到的問題是,我無法弄清楚如何做該實體的hibernate映射接收此查詢的結果,該查詢從兩個不同的表中繪製其結果。
我必須爲查詢中使用的兩個表執行hibernate映射,然後映射實體嗎?
這是工作謝謝 – JBMac 2014-09-26 20:01:40