2015-10-13 62 views
1

我试图使用我在我的类中进行的查询来检索某些数据。 我在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; 
} 

回答

0

您正在使用session.createQuery其目的是要创造HQL查询,并要执行一个SQL查询,所以尝试session.createSQLQuery代替。

+0

我不知道createSQLQuery存在!我通过使用我的类的属性名称而不是DB列的名称来解决我的问题。但也许那个createSQLQuery也可以工作:) – Majestic

+0

这是另一种选择,类属性是HQL期望的,如果你已经映射或注释为实体,显然。 – malaguna

+0

@Majestic我会感谢你,如果你接受或投票我的答案,因为它似乎对你有帮助 – malaguna

相关问题