Query queryObject = session.createSQLQuery(
? ? ? ? ? ? ? ? ? ? ? ? "select {record.*}" +
? ? ? ? ? ? ? ? ? ? ? ? " from " + tableName + " record, Vip_branch branch where branch.companyid = :companyid and branch.branchid = record.branchid order by record.time asc").
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? addEntity("record", Vip_record.class);
? ? ? ? ? ? ? ? queryObject.setLong("companyid", companyid);
? ? ? ? ? ? ? ? return queryObject.list();


其中tableName為表名

得到統計結果也是類似的:

Query queryObject = session.createSQLQuery(
? ? ? ? ? ? ? ? ? ? ? ? "select count(*) as count" +
? ? ? ? ? ? ? ? ? ? ? ? " from " + tableName +
? ? ? ? ? ? ? ? ? ? ? ? " record where record.userid = :userid").
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? addScalar("count", Hibernate.INTEGER);