Is it possible to query a datasource table from the screen controller? I’ve tried following the instructions on Running SQL Queries - CUBA Platform. Developer’s Manual, but I can’t get it to work. persistence doesn’t have a method ‘getEntityManager()’.
@Inject
private Persistence persistence;
@Subscribe
protected void onInit(InitEvent event) {
Query query = persistence.getEntityManager().createNativeQuery(
"select * from TABLE");
List list = query.getResultList();
for (Iterator it = list.iterator(); it.hasNext(); ) {
Object[] row = (Object[]) it.next();
String name = (String) row[1];
log.info(name);
}
}
}
Is this possible or is there another way to query a datasource and manipulate the results in the screen controller?
Thanks, that helps me a step forward. Suppose I want to load entities from a KeyValueDatasource. What can I best do to query the datasource and then iterate the results? I’m not sure what method listed on https://doc.cuba-platform.com/manual-7.1/dataManager.html is suitable to do that. I suspect ‘loadValues(String query)’.