求助,hibernate里面的数据库语句(sql)
public Businfo findBusName(String name) throws Exception {
String sql = "select * from businfo buin where buin.bid = (select bu.bid from busst bu join stinfo st on bu.stid = st.stid and st.stname=' ?')";
Session session = this.getSession();
List<Businfo> list = session.createSQLQuery(sql).list();
System.out.println(list.size());
if(list.size()!=0){
return list.get(0);
}
return null;
}
怎么办参数name传到sql语句中的?啊
sql?hibernate
[解决办法]
Query query = session.createSQLQuery(sql);
query.setParameter(0, name);
List list = query.list();