[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.tools.emf] Re: [Teneo] lazy fetching of many to one associations

Hi Andrew,
I don't really know how to dynamic proxying without class enhancement, so if you know more about this then let me know.


If you mean EMF proxying, I looked at EMF proxies a while back but I could not get it working with hibernate directly.

gr. Martin

Andrew H wrote:
Incidentally, given the in EMF we have interfaces for our domain models, hibernate should in theory not need to use CGLIB for proxies. Any idea if it is able to make use of this fact?

Otherwise, this may explain why hibernate was eagerly loading the oneToOnes, as I did not explicitly add CGLIB to the classpath.

Andrew H wrote:

OK thanks Martin

https://bugs.eclipse.org/bugs/show_bug.cgi?id=250230


Martin Taal wrote:

Hi Andrew,
The econtainer relation is handled using a custom type. I can check if I
can
get lazy loading
working there. Can you enter a bugzilla for this?

gr. Martin

Andrew H wrote:
So with the caveat you flagged earlier, if I annotate a class this should also work for one to one and many to one?

Incidentally, I just noticed something scary. It is eagerly fetching all eContainer relationships too.

I did a query on a very primitive class. When I did this hibernate automatically ran queries all the way up the containment hierarchy to the root.

In this case I actually wanted to get to the root anyway so it wasn't a problem, but made me think that this could be very expensive where I didn't want to get the root object but just a collection of the simple objects.

I guess the cause of this is that eContainer is a oneToOne relationship so hits the same reluctance from hibernate to lazily load.

Have you encountered this before?
Martin Taal wrote:

Hi Andrew,
Correct, the other approach is to set @Proxy on individual EClasses using
eannotations.
With SET_PROXY=true Teneo will add @Proxy to all EClasses, with
SET_PROXY=false it doesn't.

If the EClass has a @Proxy then ereferences to it will as a default have
fetch=LAZY, unless you have
set fetch=EAGER using an annotation on the ereference.

gr. Martin

Andrew H wrote:
That would make it lazy load all classes wouldn't it?

If I only want to lazily fetch a few references what is the correct way to do this?
The javadoc for SET_PROXY seems to suggest that I should have added a @Proxy annotation to the Data class - is that correct?
I presume then that I could do the same with an eannotation on the ecore class?


Is adding the annotation to the reference supposed to work (at least in the case where it works in hibernate)?

I actually want it to eagerly fetch almost everything. In fact in the example below I want it to behave as follows:

- By default don't eagerly fetch the data relationship.
- If I join fetch on data then I want the whole data object graph eagerly fetched.


I got this working yesterday as follows:
- PersistenceOptions.FETCH_CONTAINMENT_EAGERLY = true
- Change the data relationship to a one to many. This is a hack but I may have to live with it if I can't get the oneToOne to work lazily with hibernate
- Add the following annotaion to the data reference


<eStructuralFeatures xsi:type="ecore:EReference" name="data" lowerBound="1" upperBound="-1"
eType="#//Data" containment="true">
<eAnnotations source="teneo.jpa">
<details key="appinfo" value="@OneToMany(fetch=LAZY)"/>
</eAnnotations>
</eStructuralFeatures>


I may look further into getting this to work with a oneToOne later.



Martin Taal wrote:

Hi Andrew,
You can try to set the option: PersistenceOptions.SET_PROXY to true. This
will add lazy="true" to
the class mapping and also set lazy="proxy" on the many-to-ones. Note that
lazy loading and onetoone
does not always work with hibernate.
http://www.hibernate.org/162.html

gr. Martin

Andrew H wrote:
I can't seem to stop hibernate fetching a particular many to one assocation.

I have something like

Foo
-> versions : FooVersion (one To Many) -> data: Data (Many To One)


i.e. a class Foo with a oneToMany reference versions of type FooVersion. FooCersion has a single (mapped as ManyToOne) reference data of type Data. Data is a pretty large tree of objects.

I need to do stuff with the versions reference such as

foo.getVersions().get(foo.getVersions().size() - 1)

The problem is that as I do this, hibernate will load all the FooVersion objects in the versions relationship and in doing so load all the data for each version. Unfortunately, Data is large so as I add more versions this becomes increasingly expensive.

So I have been trying to stop hibernate from fetching data in these cases. If I turn data into a oneToMany relationship then I can stop it. However, I just can't seem to get it to work on a ManyToOne (and presumably OneToOne).

I've tried adding an annotation on this element in the ecore model as follows

<eStructuralFeatures xsi:type="ecore:EReference" name="data" lowerBound="1" eType="#//Data"
containment="true">
<eAnnotations source="teneo.jpa">
<details key="appinfo" value="@ManyToOne(fetch=LAZY)"/>
</eAnnotations>
</eStructuralFeatures>


But this makes no difference. Strangely in the generated hibernate mappings this still comes in as lazy="false"

I tried manually configuring the hibernate mappings as lazy="proxy" and lazy="no-proxy"

but still no joy.

Any ideas?













--

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@xxxxxxxxxxxxxx - mtaal@xxxxxxxxx
Web: www.springsite.com - www.elver.org