gpt4 book ai didi

hibernate - 将原生 SQL 查询的结果映射到 Grails 域类

转载 作者:行者123 更新时间:2023-12-03 13:54:37 39 4
gpt4 key购买 nike

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

最佳答案

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;

关于hibernate - 将原生 SQL 查询的结果映射到 Grails 域类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2088641/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com