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?