Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Teneo] lazy fetching of many to one associations
[Teneo] lazy fetching of many to one associations [message #423757] Tue, 07 October 2008 06:08 Go to next message
Andrew H is currently offline Andrew HFriend
Messages: 117
Registered: July 2009
Senior Member
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?
Re: [Teneo] lazy fetching of many to one associations [message #423762 is a reply to message #423757] Tue, 07 October 2008 08:22 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
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@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: [Teneo] lazy fetching of many to one associations [message #423845 is a reply to message #423762] Tue, 07 October 2008 23:13 Go to previous messageGo to next message
Andrew H is currently offline Andrew HFriend
Messages: 117
Registered: July 2009
Senior Member
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?
>>
Re: [Teneo] lazy fetching of many to one associations [message #423848 is a reply to message #423845] Tue, 07 October 2008 23:46 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
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@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: [Teneo] lazy fetching of many to one associations [message #423853 is a reply to message #423848] Wed, 08 October 2008 07:27 Go to previous messageGo to next message
Andrew H is currently offline Andrew HFriend
Messages: 117
Registered: July 2009
Senior Member
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?
>>>>
>>
>>
>>
>>
Re: [Teneo] lazy fetching of many to one associations [message #423888 is a reply to message #423853] Thu, 09 October 2008 00:56 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
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@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: [Teneo] lazy fetching of many to one associations [message #423890 is a reply to message #423888] Thu, 09 October 2008 05:36 Go to previous messageGo to next message
Andrew H is currently offline Andrew HFriend
Messages: 117
Registered: July 2009
Senior Member
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?
>>>>>>
>>>>
>>>>
>>>>
>>>>
>>
>>
>>
>>
Re: [Teneo] lazy fetching of many to one associations [message #423923 is a reply to message #423890] Thu, 09 October 2008 22:34 Go to previous messageGo to next message
Andrew H is currently offline Andrew HFriend
Messages: 117
Registered: July 2009
Senior Member
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?
>>>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>
>>>
>>>
>>>
Re: [Teneo] lazy fetching of many to one associations [message #423943 is a reply to message #423923] Fri, 10 October 2008 12:15 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
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@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: [Teneo] lazy fetching of many to one associations [message #423977 is a reply to message #423943] Mon, 13 October 2008 01:06 Go to previous message
Andrew H is currently offline Andrew HFriend
Messages: 117
Registered: July 2009
Senior Member
I just did a bit of googling but didn't find anything concrete. It does
hint about that it may use interfaces in 4.1.3 of
http://www.hibernate.org/hib_docs/v3/reference/en-US/html/pe rsistent-classes.html

It may be that it is already making use of the interfaces without us
needing to do anything special. When I get a chance I might try to set up
a one to one as a lazy fetch and then run it through the debugger to see
if it is cglib'ing the impl or creating a dymanic proxy of the interface.

I was refering to hibernate proxies not EMF proxies.

Martin Taal wrote:

> 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?
>>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>
>>
Previous Topic:[Teneo] Error parsing XML
Next Topic:How to create an EString to set as EType for an EAttribute
Goto Forum:
  


Current Time: Fri Apr 26 01:13:18 GMT 2024

Powered by FUDForum. Page generated in 0.03578 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top