【发布时间】:2023-03-22 17:50:01
【问题描述】:
我正在尝试在 Java Play 中使用 Ebean 2.3.3 查询部分对象!框架 2.2.1。例如,要从instance_config 表中获取仅包含字段id、host 和publicKey 的记录列表,我使用以下命令:
List<InstanceConfig> tests = Ebean.find(InstanceConfig.class)
.select("host,publicKey")
.where().eq("accountId", accountId).ne("host", "")
.findList();
这会产生以下 sql 查询,这是我所期望的:
[debug] c.j.b.PreparedStatementHandle - select t0.id as c0, t0.host as c1,
t0.public_key as c2 from instance_config t0 where t0.account_id = xxxxxxxxxx
and t0.host <> ''
但是,相同的代码也会为正在查询的表中的每条记录生成此查询:
[debug] c.j.b.PreparedStatementHandle - select t0.id as c0, t0.host as c1,
t0.public_key as c2, t0.private_key as c3, t0.created_by as c4,
t0.account_id as c5 from instance_config t0 where t0.id = xx
从服务器返回的输出包含完整的对象,以及所有的字段。
我猜这些查询与 Ebean 对部分对象所做的 Lazy Loading 有关吗?
我在SO question 中发现绕过延迟加载的一种方法是一起绕过 Ebean 并使用标准 JDBC 接口来执行查询。这个问题是几年前的问题,我想重新发布,问这个解决方案是否仍然准确?
【问题讨论】:
标签: java playframework ebean