Panache 查询具有不同的 returns PanacheQuery<Entity> 而不是 ArrayList<String>

Panache Query with distinct returns PanacheQuery<Entity> and not ArrayList<String>

我正在尝试使用 Panache+Hibernate 从我的数据库中获取一个列的不同结果。通常在 Hibernate 中,您会从查询中得到 ArrayList<String>

List<String> list = repo
            .find("select DISTINCT(a.country) from TMdBrandAll a order by a.country")
            .page(Page.ofSize(1000)).list();

但是如果我用 Panache 尝试这种方法,我会收到 ErrorMessage Comiler Error Message

如果我将变量 "list" 更改为 returnType List<TMdBrandAll>,编译错误就消失了。

List<TMdBrandAll> list = brandAllRepo
            .find("select DISTINCT(a.country) from TMdBrandAll a order by a.country")
            .page(Page.ofSize(1000)).list();

当我现在检查调试器中执行的代码时,我得到了。 Debugger output

我如何告诉 Panache 查询的结果是 ArrayList<Strings> 而不是 ArrayList<PanacheEntity>

感谢您的回答

编辑: 回购代码:

@RequestScoped
@Transactional
public class BrandAllRepo implements PanacheRepositoryBase<TMdBrandAll, Long> {


    public void updateBrand(String brandName, String soundexCode, String countryCode, Long active, Long isNew, String user, Long brandAllId) {

        update("set brandName = ?1, soundexCode = soundex(pkg_util.f_escape_special_char1(?2))," +
                " countryCode = ?3, active = ?4, isNew = ?5, modifiedAt = sysdate, modified_by = ?6 where brandAllId = ?7",
            brandName, soundexCode, countryCode, active, isNew, user, brandAllId);

    }

}

Repo 中的工作代码:

@Inject
EntityManager em;

public List<String> findCountries() {
    List<String> qres = em
        .createQuery("select DISTINCT(a.countryCode) from TMdBrandAll a order by a.countryCode", String.class)
        .getResultList();

    return new ArrayList<>(qres);
}

通过注入 EntityManager 和标准休眠查询,它可以正常工作。

这是 Panache 的限制。

看看代码https://github.com/quarkusio/quarkus/blob/master/extensions/panache/hibernate-orm-panache/runtime/src/main/java/io/quarkus/hibernate/orm/panache/PanacheRepositoryBase.java

它总是returns实体列表。

要么在 BrandAllRepo 中创建一个 returns 字符串列表的查找器方法,要么使用无类型列表:

List list = brandAllRepo
        .find("select DISTINCT(a.country) from TMdBrandAll a order by a.country")
        .page(Page.ofSize(1000)).list();

你知道列表中会有字符串。

第二个选项不太好。我会使用第一个选项。