2014-07-16 152 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);