Java 具有不同返回的Panache查询PanacheQuery<;实体>;而不是ArrayList<;字符串>;
我正在尝试使用Panache+Hibernate从数据库中获得一个列的明确结果。通常在Hibernate中,您会从查询返回一个Java 具有不同返回的Panache查询PanacheQuery<;实体>;而不是ArrayList<;字符串>;,java,hibernate,quarkus,quarkus-panache,Java,Hibernate,Quarkus,Quarkus Panache,我正在尝试使用Panache+Hibernate从数据库中获得一个列的明确结果。通常在Hibernate中,您会从查询返回一个ArrayList List<String> list = repo .find("select DISTINCT(a.country) from TMdBrandAll a order by a.country") .page(Page.ofSize(1000)).list(); List List=repo
ArrayList
List<String> list = repo
.find("select DISTINCT(a.country) from TMdBrandAll a order by a.country")
.page(Page.ofSize(1000)).list();
List List=repo
.find(“从TMdBrandAll中选择不同的(a.country)按a.country排序的订单”)
.page(第页,共页尺寸(1000)).list();
但是如果我用华丽的方式尝试这种方法,我会得到错误的信息
如果我将变量“list”更改为returnTypelist
,编译错误就消失了
List<TMdBrandAll> list = brandAllRepo
.find("select DISTINCT(a.country) from TMdBrandAll a order by a.country")
.page(Page.ofSize(1000)).list();
List List=brandAllRepo
.find(“从TMdBrandAll中选择不同的(a.country)按a.country排序的订单”)
.page(第页,共页尺寸(1000)).list();
当我现在在调试器中检查执行的代码时,我得到了。
我如何告诉Panache查询的结果将是ArrayList
,而不是ArrayList
谢谢你的回答
编辑:
回购代码:
@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);
}
}
@RequestScoped
@交易的
公共类BrandAllRepo实现PanacherRepositoryBase{
public void updateBrand(String brandName、String soundexCode、String countryCode、Long active、Long isNew、String user、Long brandAllId){
更新(“设置brandName=?1,soundexCode=soundex(pkg_util.f_escape_special_char1(?2)),”+
“countryCode=?3,active=?4,isNew=?5,modifiedAt=sysdate,modified_by=?6,其中brandAllId=?7”,
brandName、soundexCode、countryCode、active、isNew、user、brandAllId);
}
}
回购协议的工作代码:
@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);
}
@Inject
实体管理器;
公共列表查找国家(){
列表qres=em
.createQuery(“从TMdBrandAll中选择DISTINCT(a.countryCode)并按a.countryCode调用订单”,String.class)
.getResultList();
返回新的ArrayList(qres);
}
通过注入EntityManager和标准hibernate查询,它可以正常工作。这是一个华丽的限制 看看代码 它总是返回实体的列表 在BrandAllRepo中创建返回字符串列表的查找器方法,或使用非类型化列表:
List list = brandAllRepo
.find("select DISTINCT(a.country) from TMdBrandAll a order by a.country")
.page(Page.ofSize(1000)).list();
您知道列表中会有字符串
第二种选择不太好。我会使用第一个选项。这是一个华丽的限制 看看代码 它总是返回实体的列表 在BrandAllRepo中创建返回字符串列表的查找器方法,或使用非类型化列表:
List list = brandAllRepo
.find("select DISTINCT(a.country) from TMdBrandAll a order by a.country")
.page(Page.ofSize(1000)).list();
您知道列表中会有字符串
第二种选择不太好。我会使用第一个选项。请显示您的回购代码更新为回购代码请显示您的回购代码更新为回购代码