Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc) » [Teneo] Partially resolve containment references(Is there a way to resolve containment references partially only?)
| | |
Re: [Teneo] Partially resolve containment references [message #1620642 is a reply to message #1620629] |
Tue, 17 February 2015 10:24 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi Timo,
Hmm, the reference explains how to query/filter the contents of an association, so the second level, after loading the
parent/first level.
So you can create a query to read the first 10 patients sorted by last name and then for each patient load the
measurements through a collection filtered call (see the doc link of the previous post)
For the query you describe below, you can also use HQL to load this data, so you don't need to first load the patients,
you can create a query (hql) which returns tuples of patients - measurements and then sort by lastname, id. HQL has many
nice collection functions.
gr. Martin
On 17-02-15 11:15, Timo Rohrberg wrote:
> Hi Martin,
>
> thanks for your quick reply.
>
> OK, so the default behavior is lazy-loading of all contained objects. But what do you mean with "load a subset
> explicitly" and "not within the owner object"? The referred documentation just explains how to load persisted
> collections at the first level. But can I restrict the collection of contained objects?
>
> I would like to perform a query like this: "From all patients sorted alphabetically ascending for lastName give me the
> first 10 and for each of those the 10 most recent measurements" assuming that patient has a containment reference to
> measurement.
>
> Do you think there is any way to achieve something like this?
>
> Cheers
> Timo
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
|
|
| |
Re: [Teneo] Partially resolve containment references [message #1620721 is a reply to message #1620700] |
Tue, 17 February 2015 11:30 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi Timo,
Doing patient.getMeasurements() does not load the collection yet, only if you call a method on the collection it starts
loading (if needed to do the call), for example, this loads the collection: patient.getMeasurements().get(0)
The removeAll and addAll on patient.getMeasurements will remove/add these objects in the database. So not sure if you
want to do tis.
For the hql to load the measurements, it is something like this:
select p, m from Patient p, Measurement m where m in p.measurements order by p.lastName, p.id, p.date
then within the where clause you can filter on other measurements properties. The result set of the query will be a list
of arrays where each array has 2 entries: a patient and a measurement entity. One patient can occur multiple times if a
patient as multiple measurements.
It is probably difficult to limit the query to the latest 10 measurements though. But you can do inner selects and other
complexer stuff.
My impression looking at your pseudo code is that you want to create have Patient objects which have a measurements
collections which is filtered/sorted. This is however not possible, the measurements collection in the Patient will
always be the complete list of measurements, you can create a filtered separate collection instance but this is a
separate instance from the collection in Patient.
Not sure if I explain it well enough :-)
gr. Martin
On 17-02-15 12:12, Timo Rohrberg wrote:
> Hi Martin,
>
> thanks again for your reply. I am trying to understand your explanation and would like to make an example in more or
> less pseudo code.
>
> So for your first approach, I would load the first 10 patients sorted by last name and refill the collection of
> measurements of each patient using the filtered collections:
>
>
> Criteria criteria = session.createCriteria(PatientPackage.eINSTANCE.getPatient());
> criteria.addOrder(Order.asc("lastName"));
> criteria.setMaxResults(10);
> Collection<Patient> patients = criteria.list();
>
> for (Patient patient : patients) {
> Collection first10Measurements= session.createFilter(patient.getMeasurements(),
> "").setFirstResult(0).setMaxResults(10).list();
> patient.getMeasurements().removeAll();
> patient.getMeasurements().addAll(first10Measurements);
> }
>
>
> Isn't that a little bit weired? Once I touch "patient.getMeasurements()" the collection is already lazy loaded with all
> consequences on the performance?
>
> And for your second approach, I unfortunately do not get how to perform such a query for tuples, and still get the
> result as instances of modeled entities. A tuple of Patient/Measurement never matches my modeled entities Patient and
> Measurement, right?
>
> Thanks a lot for so much input you're providing. I have the feeling that we are close to a solution - I just don't get
> it completely yet...
>
> Regards
> Timo
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
|
|
|
Goto Forum:
Current Time: Tue Sep 24 18:56:54 GMT 2024
Powered by FUDForum. Page generated in 0.04565 seconds
|