2014-07-16 149 views
-1

需要幫助創建hibernate查詢,該表是jdwCustomerTlrdRef,它應該採用所有operation_spec =客戶名稱。該方法應該返回sysId。需要幫助來創建hibernate查詢

這裏是要檢查的代碼。請幫助我,我是這個hibernate查詢的新手。

公共getCustomerTlrdRef(BigDecimal的SYSID){

System.out.println("---- getAllCustomerTlrdRef "); 

String query = "from JdwCustomerTlrdRef as jdwCustomerTlrdRef where jdwCustomerTlrdRef.operation_spec= '+customer_name+'"; 
Query q = getSessionFactory().getCurrentSession().createQuery(query); 
List<JdwCustomerTlrdRef> customerTlrdRefSysId = q.list(); 

System.out.println(" List size: " + customerTlrdRefSysId.size()); 

return customerTlrdRefSysId; 

}

回答

0

這應該工作。

String query = "from JdwCustomerTlrdRef jdwCustomerTlrdRef where jdwCustomerTlrdRef.operation_spec= '+ customer_name +'"; 

否則,如果您希望稍後在代碼中傳遞參數,則以此方式進行。

String query = "FROM JdwCustomerTlrdRef jdwCustomerTlrdRef WHERE jdwCustomerTlrdRef.operation_spec = :customer_name" 

然後在你的代碼中,你可以通過這種方式傳遞參數。

query.setParameter("customer_name", theCustomerNameParameter);