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);