How to retrieve latest record in entity's Set attribute

Hi,

I was wondering what would be the best way to tackle this… I need to track a customer’s status and changes over time. My questions are:

  1. If I map the entities as attached, issues I ran into: retrieving the latest status for the customer.

customer ()>-(1) customer_status (1)-<() status

In SQL, I would use the following query:
select cs.customer.name, max(cs.date)from customer_status cs
where cs.customer.id = xyz
group by cs.customer.name

Would you suggest:
a) Defining the above in a datasource using JPQL? If so, what’s the syntax; or
b) Creating my own custom datasource, helpers, etc.?

  1. I haven’t taken a look at the BPM module yet but this sounds like it would be a fit (there is an element of state and workflow in my requirements). However, I’m guessing I would still need to resolve the issue above?

Would appreciate your thoughts on this.

Cheers,
Eddy

Hi Eddy,

  1. You can express the same in JPQL, see for example Java Persistence/JPQL - Wikibooks, open books for an open world

Keep in mind that you need datasources only if you want to display or edit loaded data in visual components. Otherwise you can load data with DataManager or (on middleware) EntityManager. If you go for a datasource, use value datasources because normal datasources cannot return scalar values and aggregates.

  1. Please ask more concrete questions or write us at info@cuba-platform.com and we’ll provide a trial subscription for you to test the BPM addon.