我試圖使用我在我的類中進行的查詢來檢索某些數據。 我在Oracle SQL Developer上試過這個查詢,它工作正常,我從這個查詢中得到了結果。 但是當我嘗試使用它throught的Java返回我一個錯誤:使用Hibernate在java中創建查詢:無法解析屬性
無法getFlightInSandbox:無法解析屬性:tacticalplanning_id的:com.atosorigin.airbus.evpt.model.Flight [選擇f.id來自com.atosorigin.airbus.evpt.model.Flight f,其中f.isinsandbox ='Y'和f.tacticalplanning_id in(選擇id來計劃其中的域如'R%')和((f.id in(select c。 flight_id from changelog c其中c.logactiontype_id in(從logactiontype l中選擇l.id,其中l.key ='APC7CREATE')))或(f.id in(從ca.logactiontype中選擇ca.flight_id ca.logactiontype_id in(select l .id from logactiontype l where l.key ='APC7CREATE'))))and f.id not in(從task中選擇flight_id,其中name ='---- APC7 UPD ----')]
public List getFlightInSandbox() throws DAOException {
if (_log.isDebugEnabled()){
_log.debug("getFlightsScheduling start ");
}
List results = new ArrayList();
try {
Session session = HibernateUtil.currentSession();
Date today = new Date();
String todayString = DataFormating.formatDate(today, EvptConstants.FORMAT_DATE);
LogCvaultImport.code(4500).info("todayString = "+todayString);
Query request = session.createQuery(
"select f.id "+
"from Flight f "+
"where f.isinsandbox = 'Y' "+
"and to_char(f.begindate,'dd/MM/YYYY') >= :var1 "+
"and f.tacticalplanning_id in (select id from planning where domain like 'R%') "+
"and ((f.id in (select c.flight_id from changelog c where c.logactiontype_id in "+
"(select l.id from logactiontype l where l.key='APC7CREATE')))"+
"or (f.id in (select ca.flight_id from changelogarchive ca where ca.logactiontype_id in "+
"(select l.id from logactiontype l where l.key='APC7CREATE')))) "+
"and f.id not in (select flight_id from task where name='----APC7 UPD----')"
);
if (_log.isDebugEnabled()){
_log.debug("getFlightInSandbox query = "+request.getQueryString());
}
request.setString("var1", todayString);
results = request.list();
if (_log.isDebugEnabled()){
_log.debug("getFlightInSandbox todayString = "+todayString);
}
} catch (Exception e) {
_log.error("Could not getFlightInSandbox : " + e.getMessage());
} finally {
if (_log.isDebugEnabled()){
_log.debug("getFlightInSandbox end ");
}
}
return results;
}
我不知道createSQLQuery存在!我通過使用我的類的屬性名稱而不是DB列的名稱來解決我的問題。但也許那個createSQLQuery也可以工作:) – Majestic
這是另一種選擇,類屬性是HQL期望的,如果你已經映射或註釋爲實體,顯然。 – malaguna
@Majestic我會感謝你,如果你接受或投票我的答案,因爲它似乎對你有幫助 – malaguna