I takes ages to reload a view for a given entity. The delay taking between 5 and 10 secs for each entity instance is from my point of view unjustified. This is the code I use:
if (!PersistenceHelper.isNew(recibo)){
recibo = AppBeans.get(Persistence.class).getEntityManager().reload(recibo, "recibo-listado-recibos-view");
}
And the view involved is like this:
Bear in mind that regarding the subobjects all views I am extending are base or local. I don’t understand why it may be taking so long… certainly Ids are huge… but I don’t know if that may suffice to cause such long retrieval latencies…
It is true that the object graph is big. However if loading it straight from db, the query retrieves results inmediately.
I believe this is not a good approach for loading entities for a report. A report needs to be fast, the longest 5 or 7 seconds, but this takes ages to load roughly 170 instances of this view, so need to address it differently… from your experience should I better load it via native sql for my JasperReport?
The point is that from time to time I need to do the same report but in preview mode (i.e. before the entities are stored in the db), so for certain tasks I need to have one version of the report for non stored instances, and another one in a native sql approach for stored entities in order no avoid long latencies.
If you are not satisfied with JPQL data loading performance, you can rewrite data loading as native SQL query or even use a Groovy band that can perform several queries, mixing JPQL and SQL data loading.
Coding data loading into a Groovy band is the most flexible way.
Thanks Alex for your explanation. I think the most compatible way to pool all requirements is to select the data via sql. In the legacy system it was done via sql, and is therefore a clue that data needs to be gathered in the most efficient manner for it to be performing from the user perspective.
I will give it a change and come back on this issue.