本文介绍了将原生 SQL 查询的结果映射到 Grails 域类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以将本机 SQL 查询的结果映射到 Grails 域类实例的集合?
Is it possible to map the result of a native SQL query to a collection of Grails domain class instances?
推荐答案 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;更多推荐
将原生 SQL 查询的结果映射到 Grails 域类
发布评论