babyfish-ct / jimmer

A revolutionary ORM framework for both java and kotlin.
Apache License 2.0
876 stars 88 forks source link

limit 结合fetchOne结果与预期不符合 #749

Closed yinzsw closed 3 weeks ago

yinzsw commented 3 weeks ago

jimmer版本: org.babyfish.jimmer:jimmer-spring-boot-starter:0.9.9 java版本: 21 示例代码:

BookFetcher edition = BookFetcher.$.edition();
BookTable T = BookTable.$;
var l = sqlClient.createQuery(T).select(T.fetch(edition)).limit(1).fetchOne();

问题描述: 我使用limit(1)想使返回结果最大为1,然后调用fetchOne()获取结果.但是执行直接报错.org.babyfish.jimmer.sql.exception.TooManyResultsException: Too many results 输出日志:


2024-11-04T02:38:20.770+08:00  INFO 50693 --- [jimmer-study] [    Test worker] o.b.jimmer.sql.runtime.ExecutorForLog    : Execute SQL===>
Purpose: QUERY
SQL: select
    tb_1_.ID,
    tb_1_.EDITION
from BOOK tb_1_
limit ? /* 2 */
JDBC response status: success
Time cost: 12ms
<===Execute SQL

Too many results
org.babyfish.jimmer.sql.exception.TooManyResultsException: Too many results
    at org.babyfish.jimmer.sql.ast.query.ConfigurableRootQuery.fetchOne(ConfigurableRootQuery.java:94)
    at org.babyfish.jimmer.sql.ast.query.TypedRootQuery.fetchOne(TypedRootQuery.java:27)
    at top.yinzsw.jimmerstudy.JimmerStudyApplicationTests.contextLoads(JimmerStudyApplicationTests.java:21)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
babyfish-ct commented 3 weeks ago

Try 0.9.10