Я пытаюсь получить отличный результат одного столбца из моей базы данных с помощью 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
Если я изменю переменную "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();
Когда я сейчас проверяю исполняемый код в отладчике, который я получаю. Вывод отладчика
Как я могу сказать 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);
}
}
Рабочий код из репо:
@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 и стандартным запросом гибернации это работает.