将原生 SQL 查询的结果映射到 Grails 域类 [英] Mapping result of a native SQL query to Grails domain class

查看:22
本文介绍了将原生 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 域类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆