Hibernate使用SQL查询返回实体类型(转载)
1.String sql = "select * from T_TMP_PUBLIC_POLICY TP"; 2.SQLQuery sqluery = session.createSQLQuery(sql).addEntity(TPublicPolicyTemporary.class); 3. 4.List tmpList = sqluery.list(); ?sess.createSQLQuery("SELECT NAME, BIRTHDATE FROM CATS") .setResultTransformer(Transformers.aliasToBean(CatDTO.class)) ?
返回多个实体
1.sess.createSQLQuery("SELECT {cat.*}, {mother.*} FROM CATS c, CATS m WHERE c.MOTHER_ID = c.ID") 2. .addEntity("cat", Cat.class) 3. .addEntity("mother", Cat.class) 4. 5.{cat.*}, 的cat 就是 addEntity(“ 里面的 cat 名称。 ?