一尘不染

本地SQL查询到Grails域类的映射结果

hibernate

是否可以将本机SQL查询的结果映射到Grails域类实例的集合?


阅读 172

收藏
2020-06-20

共1个答案

一尘不染

import com.acme.domain.*

def sessionFactory
sessionFactory = ctx.sessionFactory  // this only necessary if your are working with the Grails console/shell
def session = sessionFactory.currentSession

def query = session.createSQLQuery("select f.* from Foo where f.id = :filter)) order by f.name");
query.addEntity(com.acme.domain.Foo.class); // this defines the result type of the query
query.setInteger("filter", 88);
query.list()*.name;
2020-06-20