Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Proxy & Lazy Load on Many-To-On Association
Proxy & Lazy Load on Many-To-On Association [message #720216] Tue, 30 August 2011 07:08 Go to next message
Cristian Prevedello is currently offline Cristian Prevedello
Messages: 33
Registered: June 2011
Member
Greetings
i'm having some problems with many-to-one associations and lazy load.

Currently all my entities are marked ad lazy="true". There's no proxy turned on, and so far everything works fine, except for those many-to-one associations who are eagerly loaded.

Until now we were in alpha phase, and were just grounding the application so this issue was not important.

Now we need to start to fine tune the datalayer and loading half database in memory is not an option.

So we turned on

props.setProperty(org.eclipse.emf.teneo.PersistenceOptions.SET_PROXY,"true");

First problem is referenced entity is still eagerly loaded, and i get an exception in the eSet method of my containing entity:

public void eSet(int featureID, Object newValue) {
switch (featureID)
{
case MyPagePackage.XXXXX:
setMyReferenceProperty((MyClass)newValue);



newvalue is an HibernateProxy and is casted to MyClass throwing an exception.

The faq mentions disabling "resolve proxies" on the model: i did this but still the property is eagerly loaded.

thank you in advance.

best regards.

[Updated on: Tue, 30 August 2011 07:27]

Report message to a moderator

Re: Proxy & Lazy Load on Many-To-On Association [message #720231 is a reply to message #720216] Tue, 30 August 2011 07:47 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5332
Registered: July 2009
Senior Member
Hello,
Resolve proxies is set on the ereference.

To find out why the proxy get's loaded get the Hibernate source code and put a breakpoint in
AbstractLazyInitializer.initialize. The callstack should show what calls the proxied object. Can you post the callstack
here if you feel it is teneo/emf code?

Not sure why the CCE happens, see this part of the hibernate docs:
http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html_single/#performance-fetching-proxies

especially about the example cat/domesticcat. Could that be the issue here?

gr. Martin

On 08/30/2011 09:08 AM, cristian.prevedello wrote:
> Greetings
> i'm having some problems with many-to-one associations and lazy load.
>
> Currently all my entities are marked ad lazy="true". There's no proxy turned on, and so far everything works fine,
> except for those many-to-one associations who are eagerly loaded.
>
> Until now we were in alpha phase, and were just grounding the application so this issue was not important.
>
> Now we need to start to fine tune the datalayer and loading half database in memory is not an option.
>
> So we turned on
>
> props.setProperty(org.eclipse.emf.teneo.PersistenceOptions.SET_PROXY,"true");
>
> First problem is referenced entity is still eagerly loaded, and i get an exception in the eSet method of my containing
> entity:
>
> public void eSet(int featureID, Object newValue) {
> switch (featureID)
> {
> case MyPagePackage.XXXXX:
> setMyReferenceProperty((MyClass)newValue);
>
>
>
> newvalue is an HibernateProxy and is casted to MyClass throwing an exception.
>
> The faq mentions disabling "resolve proxies" on the model, but could not find any othe informations about. This might
> fix the lazy load problem, but what about the hibernateproxy cast problem?
>
> thank you in advance.
>
> best regards.
>


--

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: Proxy & Lazy Load on Many-To-On Association [message #720246 is a reply to message #720231] Tue, 30 August 2011 08:10 Go to previous messageGo to next message
Cristian Prevedello is currently offline Cristian Prevedello
Messages: 33
Registered: June 2011
Member

Ty Martin, as you wrote i was browsing emf.codegen code looking for reloveproxy stuff and found it. been wandering for a while looking for this option and it was under my eyes.

anyhow this is the stack :

VariabileUtente is the my container class, while ParametroQuestionario is the contained class.

with at com.ViewShape.DAO.ViewShapeDAO.loadVariabileUtenteById(ViewShapeDAO.java:600)
i'm loading an instance of VariabileUtente by Id. In the stack trace there's not sign of LazyLoad initializer

this is mapping extract of VariabileUtente

<class name="com.ViewShape.Model.ViewshapemodelFactory$6" entity-name="VariabileUtente" abstract="false" lazy="true" discriminator-value="VariabileUtente" table="`variabileutente`" proxy="com.ViewShape.Model.Base.VariabileUtente">
.
.
.
<many-to-one name="ParametriQuestionari" entity-name="ParametroQuestionario" lazy="proxy" cascade="all" foreign-key="variabileutente_parametriquestionari" insert="true" update="true" not-null="false">
<column not-null="false" unique="false" name="`parametroquestionario_parametriquestionari_e_id`"/>
</many-to-one>

mapping for ParametroQuestionario
<class name="com.ViewShape.Model.ViewshapemodelFactory$29" entity-name="ParametroQuestionario" abstract="false" lazy="true" discriminator-value="ParametroQuestionario" table="`parametroquestionario`" proxy="com.ViewShape.Model.Base.ParametroQuestionario">



java.lang.ClassCastException: org.hibernate.proxy.HibernateProxy_$$_javassist_0 cannot be cast to com.ViewShape.Model.Base.ParametroQuestionario
at com.ViewShape.Model.Base.VariabileUtente.eSet(VariabileUtente.java:2171)
at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eSet(BasicEObjectImpl.java:1081)
at org.eclipse.emf.teneo.hibernate.mapping.property.EReferencePropertyHandler.set(EReferencePropertyHandler.java:190)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.setPropertyValues(AbstractEntityTuplizer.java:583)
at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:3822)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:152)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:982)
at org.hibernate.loader.Loader.doQuery(Loader.java:857)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
at org.hibernate.loader.Loader.loadEntity(Loader.java:2037)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:86)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:76)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3268)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:496)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:477)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:227)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:285)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:152)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:1090)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:1005)
at com.Larix.Utils.DataLayer.DataLayerSessionHibernate.get(DataLayerSessionHibernate.java:87)
at com.ViewShape.DAO.ViewShapeDAO.loadVariabileUtenteById(ViewShapeDAO.java:600)
at com.ViewShape.ViewShapeModel.tests.ViewShapeModelSearchTests.TestLoadForMultipleJoin(ViewShapeModelSearchTests.java:91)
Re: Proxy &amp;amp; Lazy Load on Many-To-On Association [message #720252 is a reply to message #720246] Tue, 30 August 2011 08:29 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5320
Registered: July 2009
Senior Member
Hi,

I can remember having had the same problem and the only solution for us
was to remove the generated proxy="..." in a postprocessing step because
we are loading a pregenerated hbm.xml-File this is not really a problem
to us.

The code looks like this:

> private File generateHbmXML(Properties hibernateProps, File outDir,
> Class<?> dialect, Class<?> idMapper) throws Exception {
> File hbmXML = new File(outDir, dialect.getSimpleName()
> + "-hibernate.hbm.xml");
> ExtensionManager extensionManager = ExtensionManagerFactory
> .getInstance().create();
> extensionManager.registerExtension(IdMapper.class.getName(),
> idMapper.getName());
> extensionManager.registerExtension(SQLNameStrategy.class.getName(),
> BizerbaSQLNameStrategy.class.getName());
>
> String mapping = HbHelper.INSTANCE.generateMapping(
> new EPackage[] { RetailPackage.eINSTANCE }, hibernateProps,
> extensionManager);
> FileWriter writer = new FileWriter(hbmXML);
> // Last fix up else we get JavaAssist errors
> mapping = mapping.replaceAll("proxy=\"com\\.(\\w+\\.?)*\"", "");
> writer.write(mapping);
> writer.close();
>
> return hbmXML;
> }

Tom

Am 30.08.11 10:10, schrieb cristian.prevedello:
>
> Ty Martin, as you wrote i was browsing emf.codegen code looking for
> reloveproxy stuff and found it. been wandering for a while looking for
> this option and it was under my eyes.
>
> anyhow this is the stack :
>
> VariabileUtente is the my container class, while ParametroQuestionario
> is the contained class.
>
> with at
> com.ViewShape.DAO.ViewShapeDAO.loadVariabileUtenteById(ViewShapeDAO.java:600)
>
> i'm loading an instance of VariabileUtente by Id. In the stack trace
> there's not sign of LazyLoad initializer
>
> this is mapping extract of VariabileUtente
>
> <class name="com.ViewShape.Model.ViewshapemodelFactory$6"
> entity-name="VariabileUtente" abstract="false" lazy="true"
> discriminator-value="VariabileUtente" table="`variabileutente`"
> proxy="com.ViewShape.Model.Base.VariabileUtente">
> .
> .
> .
> <many-to-one name="ParametriQuestionari"
> entity-name="ParametroQuestionario" lazy="proxy" cascade="all"
> foreign-key="variabileutente_parametriquestionari" insert="true"
> update="true" not-null="false">
> <column not-null="false" unique="false"
> name="`parametroquestionario_parametriquestionari_e_id`"/>
> </many-to-one>
>
> mapping for ParametroQuestionario
> <class name="com.ViewShape.Model.ViewshapemodelFactory$29"
> entity-name="ParametroQuestionario" abstract="false" lazy="true"
> discriminator-value="ParametroQuestionario"
> table="`parametroquestionario`"
> proxy="com.ViewShape.Model.Base.ParametroQuestionario">
>
>
>
> java.lang.ClassCastException:
> org.hibernate.proxy.HibernateProxy_$$_javassist_0 cannot be cast to
> com.ViewShape.Model.Base.ParametroQuestionario
> at
> com.ViewShape.Model.Base.VariabileUtente.eSet(VariabileUtente.java:2171)
> at
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eSet(BasicEObjectImpl.java:1081)
>
> at
> org.eclipse.emf.teneo.hibernate.mapping.property.EReferencePropertyHandler.set(EReferencePropertyHandler.java:190)
>
> at
> org.hibernate.tuple.entity.AbstractEntityTuplizer.setPropertyValues(AbstractEntityTuplizer.java:583)
>
> at
> org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:3822)
>
> at
> org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:152)
> at
> org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:982)
>
> at org.hibernate.loader.Loader.doQuery(Loader.java:857)
> at
> org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
>
> at org.hibernate.loader.Loader.loadEntity(Loader.java:2037)
> at
> org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:86)
>
> at
> org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:76)
>
> at
> org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3268)
>
> at
> org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:496)
>
> at
> org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:477)
>
> at
> org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:227)
>
> at
> org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:285)
>
> at
> org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:152)
>
> at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:1090)
> at org.hibernate.impl.SessionImpl.get(SessionImpl.java:1005)
> at
> com.Larix.Utils.DataLayer.DataLayerSessionHibernate.get(DataLayerSessionHibernate.java:87)
>
> at
> com.ViewShape.DAO.ViewShapeDAO.loadVariabileUtenteById(ViewShapeDAO.java:600)
>
> at
> com.ViewShape.ViewShapeModel.tests.ViewShapeModelSearchTests.TestLoadForMultipleJoin(ViewShapeModelSearchTests.java:91)
>
>
Re: Proxy &amp;amp; Lazy Load on Many-To-On Association [message #720253 is a reply to message #720246] Tue, 30 August 2011 08:31 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5332
Registered: July 2009
Senior Member
Hmm, I mean the stacktrace when you put a breakpoint in the initialize method of the AbstractLazyInitializer, that will
show what code forces the proxy load.

The names of the classes in the mapping seem very strange (with $29 and $6), where is this coming from? It could be related.

gr. Martin

On 08/30/2011 10:10 AM, cristian.prevedello wrote:
>
> Ty Martin, as you wrote i was browsing emf.codegen code looking for reloveproxy stuff and found it. been wandering for a
> while looking for this option and it was under my eyes.
>
> anyhow this is the stack :
>
> VariabileUtente is the my container class, while ParametroQuestionario is the contained class.
>
> with at com.ViewShape.DAO.ViewShapeDAO.loadVariabileUtenteById(ViewShapeDAO.java:600)
> i'm loading an instance of VariabileUtente by Id. In the stack trace there's not sign of LazyLoad initializer
>
> this is mapping extract of VariabileUtente
>
> <class name="com.ViewShape.Model.ViewshapemodelFactory$6" entity-name="VariabileUtente" abstract="false" lazy="true"
> discriminator-value="VariabileUtente" table="`variabileutente`" proxy="com.ViewShape.Model.Base.VariabileUtente">
> .
> .
> .
> <many-to-one name="ParametriQuestionari" entity-name="ParametroQuestionario" lazy="proxy" cascade="all"
> foreign-key="variabileutente_parametriquestionari" insert="true" update="true" not-null="false">
> <column not-null="false" unique="false" name="`parametroquestionario_parametriquestionari_e_id`"/>
> </many-to-one>
>
> mapping for ParametroQuestionario
> <class name="com.ViewShape.Model.ViewshapemodelFactory$29" entity-name="ParametroQuestionario" abstract="false"
> lazy="true" discriminator-value="ParametroQuestionario" table="`parametroquestionario`"
> proxy="com.ViewShape.Model.Base.ParametroQuestionario">
>
>
>
> java.lang.ClassCastException: org.hibernate.proxy.HibernateProxy_$$_javassist_0 cannot be cast to
> com.ViewShape.Model.Base.ParametroQuestionario
> at com.ViewShape.Model.Base.VariabileUtente.eSet(VariabileUtente.java:2171)
> at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eSet(BasicEObjectImpl.java:1081)
> at org.eclipse.emf.teneo.hibernate.mapping.property.EReferencePropertyHandler.set(EReferencePropertyHandler.java:190)
> at org.hibernate.tuple.entity.AbstractEntityTuplizer.setPropertyValues(AbstractEntityTuplizer.java:583)
> at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:3822)
> at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:152)
> at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:982)
> at org.hibernate.loader.Loader.doQuery(Loader.java:857)
> at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
> at org.hibernate.loader.Loader.loadEntity(Loader.java:2037)
> at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:86)
> at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:76)
> at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3268)
> at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:496)
> at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:477)
> at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:227)
> at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:285)
> at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:152)
> at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:1090)
> at org.hibernate.impl.SessionImpl.get(SessionImpl.java:1005)
> at com.Larix.Utils.DataLayer.DataLayerSessionHibernate.get(DataLayerSessionHibernate.java:87)
> at com.ViewShape.DAO.ViewShapeDAO.loadVariabileUtenteById(ViewShapeDAO.java:600)
> at com.ViewShape.ViewShapeModel.tests.ViewShapeModelSearchTests.TestLoadForMultipleJoin(ViewShapeModelSearchTests.java:91)
>


--

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: Proxy &amp;amp; Lazy Load on Many-To-On Association [message #720287 is a reply to message #720253] Tue, 30 August 2011 10:20 Go to previous messageGo to next message
Cristian Prevedello is currently offline Cristian Prevedello
Messages: 33
Registered: June 2011
Member

Well AbstractLazyInitializer.initialize is never called...this means the reference is eagerly loaded? It seems it's not a lazy loaded problem then?

about the Factory$ no clue. that's the mapping generated from teneo.

i thought it was proxy stuff. A side one we are not using interfaces for our entities but just plain class (which are not final), so all the proxy stuff should work.

i'm really lost will do some other testing otherwise i'll be forced to rip off from the model some references and will code them by hand.
Re: Proxy &amp;amp;amp; Lazy Load on Many-To-On Association [message #720296 is a reply to message #720287] Tue, 30 August 2011 10:31 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5332
Registered: July 2009
Senior Member
Is it easy for me to reproduce this? If so, then if you can zip something up and email it directly, then I can take a look.

gr. Martin

On 08/30/2011 12:20 PM, cristian.prevedello wrote:
>
> Well AbstractLazyInitializer.initialize is never called...this means the reference is eagerly loaded? It seems it's not
> a lazy loaded problem then?
>
> about the Factory$ no clue. that's the mapping generated from teneo.
>
> i thought it was proxy stuff. A side one we are not using interfaces for our entities but just plain class (which are
> not final), so all the proxy stuff should work.
>
> i'm really lost will do some other testing otherwise i'll be forced to rip off from the model some references and will
> code them by hand.


--

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: Proxy &amp;amp;amp; Lazy Load on Many-To-On Association [message #720815 is a reply to message #720296] Wed, 31 August 2011 09:39 Go to previous messageGo to next message
Cristian Prevedello is currently offline Cristian Prevedello
Messages: 33
Registered: June 2011
Member
Well before forcing you to dig into the package i tried to solve the problem.

Digging more into the problem i discovered several problems:

First of all all my entities were marked as lazy="false". i guess with all the tests i made i got screwed up the configuration. This caused the eager load of all entities.

To fix this i extracted the mapping, saved to an xml and updated, setting all my entities as as lazy loadable and now lazy loading was working. Tried to turn on proxy configuration option and again lazy loading was working.

At this point things improved a bit. References are not eagerly loaded, but the ESet method on my entites throws an exception. To fix the problem i had to do something like this in eSet, but this causes the reference to be lazy loaded.

case ViewshapemodelPackage.VARIABILE_UTENTE__CONFIGURAZIONE_QUESTIONARIO_STANDARD:
setConfigurazioneQuestionarioStandard((QuestionarioStandard)((HibernateProxy)newValue).getHibernateLazyInitializer().getImplementation());


kinda lost at this point. Hibernate proxy should derive from my base classes, so i should be able be casted to model classes without problem, right?



[Updated on: Wed, 31 August 2011 16:30]

Report message to a moderator

Re: Proxy &amp;amp;amp;amp; Lazy Load on Many-To-On Association [message #721042 is a reply to message #720815] Wed, 31 August 2011 18:30 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5332
Registered: July 2009
Senior Member
Hi Cristian,
I published a new teneo build with a new PersistenceOption: PersistenceOptions.FORCE_LAZY (default is false, you need to
set it to true), the full option name is teneo.mapping.force_lazy. Can you try with setting this option to true?
And set the SET_PROXY option to false. This should force lazy="true" in the mapping without the proxy attribute.

The entity which gets loaded in your stack trace, is that the entity you are requesting in
DataLayerSessionHibernate.get, if so, then this is correct, when you get an instance directly with get it is not lazy
loaded/proxied. The same applies when reading instances with a query. Basically only many-to-one associations are
possibly lazily loaded.

The exception you are getting is not 'normal', my feel is that somehow the mapping does not contain the correct
information. Can you retry with the new option above?

gr. Martin

On 08/31/2011 11:39 AM, cristian.prevedello wrote:
>
> Well before forcing you to dig into the package i tried to solve the problem.
>
> Digging more into the problem i discovered several problems:
>
> First of all all my entities are marked as lazy="false". This cause the eager load of all entities. What can cause the
> lazy="false"?
> To fix this i extracted the mapping, saved to an xml and updated, setting all my entities as as lazy loadable.
>
> At this point things improved a bit. References not eagerly loaded, but there's something that still try to lazy load
> them. Now AbstractInitilizer is hit. here is the stack:
>
>
> Thread [main] (Suspended (breakpoint at line 165 in AbstractLazyInitializer))
> JavassistLazyInitializer(AbstractLazyInitializer).initialize() line: 165
> JavassistLazyInitializer(AbstractLazyInitializer).getImplementation() line: 215
> ViewshapemodelFactory$6(VariabileUtente).eSet(int, Object) line: 2205
> ViewshapemodelFactory$6(BasicEObjectImpl).eSet(EStructuralFeature, Object) line: 1081
> EReferencePropertyHandler.set(Object, Object, SessionFactoryImplementor) line: 190
> EMFTuplizer(AbstractEntityTuplizer).setPropertyValues(Object, Object[]) line: 583
> SingleTableEntityPersister(AbstractEntityPersister).setPropertyValues(Object, Object[], EntityMode) line: 3822
> TwoPhaseLoad.initializeEntity(Object, boolean, SessionImplementor, PreLoadEvent, PostLoadEvent) line: 152
> EntityLoader(Loader).initializeEntitiesAndCollections(List, Object, SessionImplementor, boolean) line: 982
> EntityLoader(Loader).doQuery(SessionImplementor, QueryParameters, boolean) line: 857
> EntityLoader(Loader).doQueryAndInitializeNonLazyCollections(SessionImplementor, QueryParameters, boolean) line: 274
> EntityLoader(Loader).loadEntity(SessionImplementor, Object, Type, Object, String, Serializable, EntityPersister,
> LockOptions) line: 2037
> EntityLoader(AbstractEntityLoader).load(SessionImplementor, Object, Object, Serializable, LockOptions) line: 86
> EntityLoader(AbstractEntityLoader).load(Serializable, Object, SessionImplementor, LockOptions) line: 76
> SingleTableEntityPersister(AbstractEntityPersister).load(Serializable, Object, LockOptions, SessionImplementor) line: 3268
> DefaultLoadEventListener.loadFromDatasource(LoadEvent, EntityPersister, EntityKey, LoadEventListener$LoadType) line: 496
> DefaultLoadEventListener.doLoad(LoadEvent, EntityPersister, EntityKey, LoadEventListener$LoadType) line: 477
> DefaultLoadEventListener.load(LoadEvent, EntityPersister, EntityKey, LoadEventListener$LoadType) line: 227
> DefaultLoadEventListener.proxyOrLoad(LoadEvent, EntityPersister, EntityKey, LoadEventListener$LoadType) line: 285
> DefaultLoadEventListener.onLoad(LoadEvent, LoadEventListener$LoadType) line: 152
> SessionImpl.fireLoad(LoadEvent, LoadEventListener$LoadType) line: 1090
> SessionImpl.get(String, Serializable) line: 1005
> DataLayerSessionHibernate.get(String, Serializable) line: 87
> ViewShapeDAO.loadVariabileUtenteById(long) line: 597
> ViewShapeTestData.SetupTestData() line: 85
>
>
> Anyway beside lazyloading problem i've still the issue that lazy load entities are proxy, and eSet throws an exception.
> To fix it i had to do something like this in eSet.
>
> case ViewshapemodelPackage.VARIABILE_UTENTE__CONFIGURAZIONE_QUESTIONARIO_STANDARD:
> setConfigurazioneQuestionarioStandard((QuestionarioStandard)((HibernateProxy)newValue).getHibernateLazyInitializer().getImplementation());
>
>
>
> is this normal?
>
>
>
>


--

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: Proxy &amp;amp;amp;amp; Lazy Load on Many-To-On Association [message #721103 is a reply to message #721042] Wed, 31 August 2011 21:30 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5320
Registered: July 2009
Senior Member
Am 31.08.11 20:30, schrieb Martin Taal:
> Hi Cristian,
> I published a new teneo build with a new PersistenceOption:
> PersistenceOptions.FORCE_LAZY (default is false, you need to set it to
> true), the full option name is teneo.mapping.force_lazy. Can you try
> with setting this option to true?
> And set the SET_PROXY option to false. This should force lazy="true" in
> the mapping without the proxy attribute.
>

Martin this is exactly what we are using in our teneo application (but
we did it by postprocessing the hbm.xml)

Tom
Re: Proxy &amp;amp;amp;amp; Lazy Load on Many-To-On Association [message #721107 is a reply to message #721103] Wed, 31 August 2011 21:43 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5332
Registered: July 2009
Senior Member
Yes, your remark triggered me to add this! so let's hope it helps...

gr. Martin

On 08/31/2011 11:30 PM, Tom Schindl wrote:

> Am 31.08.11 20:30, schrieb Martin Taal:
>> Hi Cristian,
>> I published a new teneo build with a new PersistenceOption:
>> PersistenceOptions.FORCE_LAZY (default is false, you need to set it to
>> true), the full option name is teneo.mapping.force_lazy. Can you try
>> with setting this option to true?
>> And set the SET_PROXY option to false. This should force lazy="true" in
>> the mapping without the proxy attribute.
>>
>
> Martin this is exactly what we are using in our teneo application (but
> we did it by postprocessing the hbm.xml)
>
> Tom


--

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: Proxy &amp;amp;amp;amp; Lazy Load on Many-To-On Association [message #721208 is a reply to message #721107] Thu, 01 September 2011 07:36 Go to previous messageGo to next message
Cristian Prevedello is currently offline Cristian Prevedello
Messages: 33
Registered: June 2011
Member
I downloaded your latest build but the new option is not working as expected.

New code should be this, right?


//-------------- THIS IF IS NEVER TRUE SINCE SetProxy is false
// automatically add the proxy annotation
if (optionSetProxy && hbClass.getHbProxy() == null) {
// in this case use the DynamicEObjectImpl
if (concreteClass == null) {
concreteClass = DynamicEObjectImpl.class;
}
if (concreteClass != null || getPersistenceOptions().isForceLazy()) {
final Proxy proxy = HbannotationFactory.eINSTANCE.createProxy();
proxy.setLazy(true);
// interface class is set below.
((HbAnnotatedEClass) aClass).setHbProxy(proxy);
log.debug("Set proxy to true (" + proxy.getProxyClass()
+ ") for eclass " + aClass.getModelEClass().getName());
}
}

//-------------- THIS IF IS NEVER TRUE SINCE hbClass.getHbProxy() is always null for me.

if (hbClass.getHbProxy() != null && concreteClass != null) {
// todo add check that there is an impl class
aClass.setOnlyMapAsEntity(false);

// set interfacename if not set
if (!getPersistenceOptions().isForceLazy()) {
final Proxy proxy = hbClass.getHbProxy();
final Class<?> interfaceClass = EModelResolver.instance()
.getJavaInterfaceClass(eclass);
if (interfaceClass != null) {
proxy.setProxyClass(interfaceClass.getName());
} else { // set the class itself
proxy.setProxyClass(concreteClass.getName());
}
}
}

Beside this, i already tried to feed teneo a mapping file, where i ripped off proxy attributes and just set lazy="true".

i get the cast exception.

i tried to feed

<class name="com.ViewShape.Model.ViewshapemodelFactory$10" entity-name="QuestionarioStandard" abstract="false" lazy="true" discriminator-value="QuestionarioStandard" table="`questionariostandard`" proxy="com.ViewShape.Model.ViewshapemodelFactory$10">

and

<class name="com.ViewShape.Model.ViewshapemodelFactory$10" entity-name="QuestionarioStandard" abstract="false" lazy="true" discriminator-value="QuestionarioStandard" table="`questionariostandard`" proxy="com.ViewShape.Model.Base.QuestionarioStandard">

and

<class name="com.ViewShape.Model.ViewshapemodelFactory$10" entity-name="QuestionarioStandard" abstract="false" lazy="true" discriminator-value="QuestionarioStandard" table="`questionariostandard`" >

but none works. the eSet method explodes because the cast. now i'm going to hunt down where the proxy is created...




Re: Proxy &amp;amp;amp;amp; Lazy Load on Many-To-On Association [message #721240 is a reply to message #721208] Thu, 01 September 2011 08:57 Go to previous messageGo to next message
Cristian Prevedello is currently offline Cristian Prevedello
Messages: 33
Registered: June 2011
Member
Oh well i finally discovered the problem. Javassist does not work when it comes to extend a class. It works well when it creates a proxy throught an interface.

In our model generation, we suppressed the usage of interfaces. In our service layer, we create a lot of new instances of our model classes for exchanging infos with our DTOs.

Default generation behaviour is to generate an interface and a corresponding implementation class ( MyEntity and MyEntityImpl), and we did not want to pollute our service layer, with new MyEntityImpl() statments. So we killed interfaces as a quick fix for that.

Now i have to code on my workunit object methos to allocate entity Implementations returned as interfaces.

Not sure if cglib works better on this side, anyhow from first tests in my testcase everything work as expected, lazy load included. yeppa.

Ty Martin for the help. Own you a bear anyhow Smile
Re: Proxy &amp;amp;amp;amp;amp; Lazy Load on Many-To-On Association [message #721259 is a reply to message #721208] Thu, 01 September 2011 09:02 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5332
Registered: July 2009
Senior Member
I published a new build which hopefully helps with the force lazy thing.

For the CCE, this must be related to the strange classname in the hibernate mapping (the one with the $ in it). The
classname is determined when the mapping is generated.
How do you initialize the datastore?

gr. Martin

On 09/01/2011 09:36 AM, cristian.prevedello wrote:
> I downloaded your latest build but the new option is not working as expected.
>
> New code should be this, right?
>
>
> //-------------- THIS IF IS NEVER TRUE SINCE SetProxy is false
> // automatically add the proxy annotation
> if (optionSetProxy && hbClass.getHbProxy() == null) {
> // in this case use the DynamicEObjectImpl
> if (concreteClass == null) {
> concreteClass = DynamicEObjectImpl.class;
> }
> if (concreteClass != null || getPersistenceOptions().isForceLazy()) {
> final Proxy proxy = HbannotationFactory.eINSTANCE.createProxy();
> proxy.setLazy(true);
> // interface class is set below.
> ((HbAnnotatedEClass) aClass).setHbProxy(proxy);
> log.debug("Set proxy to true (" + proxy.getProxyClass()
> + ") for eclass " + aClass.getModelEClass().getName());
> }
> }
>
> //-------------- THIS IF IS NEVER TRUE SINCE hbClass.getHbProxy() is always null for me.
>
> if (hbClass.getHbProxy() != null && concreteClass != null) {
> // todo add check that there is an impl class
> aClass.setOnlyMapAsEntity(false);
>
> // set interfacename if not set
> if (!getPersistenceOptions().isForceLazy()) {
> final Proxy proxy = hbClass.getHbProxy();
> final Class<?> interfaceClass = EModelResolver.instance()
> .getJavaInterfaceClass(eclass);
> if (interfaceClass != null) {
> proxy.setProxyClass(interfaceClass.getName());
> } else { // set the class itself
> proxy.setProxyClass(concreteClass.getName());
> }
> }
> }
>
> Beside this, i already tried to feed teneo a mapping file, where i ripped off proxy attributes and just set lazy="true".
>
> i get the cast exception.
>
> i tried to feed
> <class name="com.ViewShape.Model.ViewshapemodelFactory$10" entity-name="QuestionarioStandard" abstract="false"
> lazy="true" discriminator-value="QuestionarioStandard" table="`questionariostandard`"
> proxy="com.ViewShape.Model.ViewshapemodelFactory$10">
>
> and
> <class name="com.ViewShape.Model.ViewshapemodelFactory$10" entity-name="QuestionarioStandard" abstract="false"
> lazy="true" discriminator-value="QuestionarioStandard" table="`questionariostandard`"
> proxy="com.ViewShape.Model.Base.QuestionarioStandard">
>
> and
> <class name="com.ViewShape.Model.ViewshapemodelFactory$10" entity-name="QuestionarioStandard" abstract="false"
> lazy="true" discriminator-value="QuestionarioStandard" table="`questionariostandard`" >
>
> but none works. the eSet method explodes because the cast. now i'm going to hunt down where the proxy is created...
>
>
>
>
>


--

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: Proxy &amp;amp;amp;amp;amp; Lazy Load on Many-To-On Association [message #721260 is a reply to message #721240] Thu, 01 September 2011 09:16 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5332
Registered: July 2009
Senior Member
Okay, good to hear, another project (I am leading to :-), which might be interesting is Texo:
http://wiki.eclipse.org/Texo

It generates simpler code than EMF, while still integrating with EMF for model-features and xml/xmi serialization, the
generated code works out of the box on a standard ORM like hibernate. Texo also makes it easy to generate the orm.xml
directly from ecore.

Texo is currently mostly for the server side of (web-)server/service environments. So not for rcp's.

gr. Martin

On 09/01/2011 10:57 AM, cristian.prevedello wrote:
> Oh well i finally discovered the problem. Javassist does not work when it comes to extend a class. It works well when it
> creates a proxy throught an interface.
> to
> In our model generation, we suppressed the usage of interfaces. In our service layer, we create a lot of new instances
> of our model classes for exchanging infos with our DTOs.
>
> Default generation behaviour is to generate an interface and a corresponding implementation class ( MyEntity and
> MyEntityImpl), and we did not want to pollute our service layer, with new MyEntityImpl() statments. So we killed
> interfaces as a quick fix for that.
> Now i have to code on my workunit object methos to allocate entity Implementations returned as interfaces.
> Not sure if cglib works better on this side, anyhow from first tests in my testcase everything work as expected, lazy
> load included. yeppa.
>
> Ty Martin for the help. Own you a bear anyhow :)


--

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: Proxy &amp;amp;amp;amp;amp; Lazy Load on Many-To-On Association [message #814255 is a reply to message #721260] Tue, 06 March 2012 08:16 Go to previous messageGo to next message
Cristian Prevedello is currently offline Cristian Prevedello
Messages: 33
Registered: June 2011
Member
Greetings Marting, how are you? Hope things are going well on your side.

i'm briging up this old post again because new issues about lazy loading ManyToOne came up.

The datamodel is

Class RisultatiQuestinario 1---1 OutputRisposte

the reference is not bidirectional, that is risultatiquestionario has a link to outputrisposte, but not the reverse. And the reference is set as not optional, and with resolveproxy to false.

the generated mappings are

<class name="com.xxx.Model.impl.RisultatiQuestionarioImpl" entity-name="RisultatiQuestionario" abstract="false" lazy="true" discriminator-value="RisultatiQuestionario" table="`risultatiquestionario`" proxy="com.ViewShape.Model.Base.RisultatiQuestionario">
      <id name="Id" type="long" unsaved-value="0">
         <column not-null="true" unique="false" name="`id`"/>
         <generator class="native"/>
      </id>
      <discriminator type="string">
         <column name="dtype" index="risultatiquestionariodtype" length="255" not-null="true"/>
      </discriminator>
      <version name="e_version" type="int">
         <column not-null="true" unique="false" name="`e_version`"/>
      </version>
      <many-to-one name="Risposte" entity-name="OutputRisposte" lazy="proxy" cascade="all" foreign-key="risultatiquestionario_risposte" insert="true" update="true" not-null="true" unique="true">
         <column not-null="true" unique="false" name="`outputrisposte_risposte_e_id`"/>
      </many-to-one>
.
.
.

   <class name="com.xxx.Model.impl.OutputRisposteImpl" entity-name="OutputRisposte" abstract="false" lazy="true" discriminator-value="OutputRisposte" table="`outputrisposte`" proxy="com.ViewShape.Model.Base.OutputRisposte">



The problem is, whenever i load a RisultatiQuestionario class, OutputRisposte is eagerly loaded.

as suggested from hibernate forum i put a breakpoint into immediateload in session hibernate to see what's firing the load.

Thread [main] (Suspended)	
	JavassistLazyInitializer.invoke(Object, Method, Method, Object[]) line: 190	
	OutputRisposte_$$_javassist_32.eInverseAdd(InternalEObject, int, Class, NotificationChain) line: not available	
	RisultatiQuestionarioImpl.setRisposte(OutputRisposte) line: 491	
	RisultatiQuestionarioImpl.eSet(int, Object) line: 1368	
	RisultatiQuestionarioImpl(BasicEObjectImpl).eSet(EStructuralFeature, Object) line: 1081	
	EReferencePropertyHandler.set(Object, Object, SessionFactoryImplementor) line: 190	
	EMFTuplizer(AbstractEntityTuplizer).setPropertyValues(Object, Object[]) line: 583	
	SingleTableEntityPersister(AbstractEntityPersister).setPropertyValues(Object, Object[], EntityMode) line: 3822	
	TwoPhaseLoad.initializeEntity(Object, boolean, SessionImplementor, PreLoadEvent, PostLoadEvent) line: 152	
	QueryLoader(Loader).initializeEntitiesAndCollections(List, Object, SessionImplementor, boolean) line: 982	
	QueryLoader(Loader).doQuery(SessionImplementor, QueryParameters, boolean) line: 857	
	QueryLoader(Loader).doQueryAndInitializeNonLazyCollections(SessionImplementor, QueryParameters, boolean) line: 274	
	QueryLoader(Loader).doList(SessionImplementor, QueryParameters) line: 2533	
	QueryLoader(Loader).listIgnoreQueryCache(SessionImplementor, QueryParameters) line: 2276	
	QueryLoader(Loader).list(SessionImplementor, QueryParameters, Set, Type[]) line: 2271	
	QueryLoader.list(SessionImplementor, QueryParameters) line: 452	
	QueryTranslatorImpl.list(SessionImplementor, QueryParameters) line: 363	
	HQLQueryPlan.performList(QueryParameters, SessionImplementor) line: 196	
	SessionImpl.list(String, QueryParameters) line: 1268	
	QueryImpl.list() line: 102	
	DataLayerSessionHibernate.Query(String, Object...) line: 143	
	ViewShapeDAO.Query(String) line: 176	
	ViewShapeModelTestsSearch.TestGetListaRisultati() line: 838	
	NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]	
	NativeMethodAccessorImpl.invoke(Object, Object[]) line: 39	
	DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25	
	Method.invoke(Object, Object...) line: 597	
	FrameworkMethod$1.runReflectiveCall() line: 44	
	FrameworkMethod$1(ReflectiveCallable).run() line: 15	
	FrameworkMethod.invokeExplosively(Object, Object...) line: 41	
	InvokeMethod.evaluate() line: 20	
	RunBefores.evaluate() line: 28	
	BlockJUnit4ClassRunner.runChild(FrameworkMethod, RunNotifier) line: 76	
	BlockJUnit4ClassRunner.runChild(Object, RunNotifier) line: 50	
	ParentRunner$3.run() line: 193	
	ParentRunner$1.schedule(Runnable) line: 52	
	BlockJUnit4ClassRunner(ParentRunner<T>).runChildren(RunNotifier) line: 191	
	ParentRunner<T>.access$000(ParentRunner, RunNotifier) line: 42	
	ParentRunner$2.evaluate() line: 184	
	RunBefores.evaluate() line: 28	
	BlockJUnit4ClassRunner(ParentRunner<T>).run(RunNotifier) line: 236	
	JUnit4TestMethodReference(JUnit4TestReference).run(TestExecution) line: 49	
	TestExecution.run(ITestReference[]) line: 38	
	RemoteTestRunner.runTests(String[], String, TestExecution) line: 467	
	RemoteTestRunner.runTests(TestExecution) line: 683	
	RemoteTestRunner.run() line: 390	
	RemoteTestRunner.main(String[]) line: 197	


when calling eInverseAdd method, the proxy is loaded and hits the database.

ty for your help.


Re: Proxy &amp;amp;amp;amp;amp;amp; Lazy Load on Many-To-On Association [message #814284 is a reply to message #814255] Tue, 06 March 2012 09:03 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5332
Registered: July 2009
Senior Member
Hi,
Hmm, I read a bit through the thread, but what are your current problems?

gr. Martin

On 03/06/2012 09:16 AM, Missing name Mising name wrote:
> Greetings Marting, how are you? Hope things are going well on your side.
>
> i'm briging up this old post again because new issues about lazy loading ManyToOne came up.
>
> The datamodel is
>
> Class RisultatiQuestinario 1---1 OutputRisposte
>
> the reference is not bidirectional, that is risultatiquestionario has a link to outputrisposte, but not the reverse. And
> the reference is set as not optional, and with resolveproxy to false.
>
> the generated mappings are
>
> <class name="com.xxx.Model.impl.RisultatiQuestionarioImpl" entity-name="RisultatiQuestionario" abstract="false"
> lazy="true" discriminator-value="RisultatiQuestionario" table="`risultatiquestionario`"
> proxy="com.ViewShape.Model.Base.RisultatiQuestionario">
> <id name="Id" type="long" unsaved-value="0">
> <column not-null="true" unique="false" name="`id`"/>
> <generator class="native"/>
> </id>
> <discriminator type="string">
> <column name="dtype" index="risultatiquestionariodtype" length="255" not-null="true"/>
> </discriminator>
> <version name="e_version" type="int">
> <column not-null="true" unique="false" name="`e_version`"/>
> </version>
> <many-to-one name="Risposte" entity-name="OutputRisposte" lazy="proxy" cascade="all"
> foreign-key="risultatiquestionario_risposte" insert="true" update="true" not-null="true" unique="true">
> <column not-null="true" unique="false" name="`outputrisposte_risposte_e_id`"/>
> </many-to-one>


--

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: Proxy &amp;amp;amp;amp;amp;amp; Lazy Load on Many-To-On Association [message #814292 is a reply to message #814284] Tue, 06 March 2012 09:22 Go to previous messageGo to next message
Cristian Prevedello is currently offline Cristian Prevedello
Messages: 33
Registered: June 2011
Member
maybe i should have opened a new thread, since my current problem is not exatly related to what i described previosuly in the thread.

right now, entities are not lazy loaded but eagerly loaded.

RisulatoQuestionario in the model has a one way 1-1 relation with Outputrisposte

the mapping generated is the one in my previous post. The problem is whenever i load 1 risultatoquestonario, outputrisposte is loaded as well. Debugging throught the code,
i tracked down the moment the outputrisposte is loaded.

When RisultatoQuestionario is materialized, hibernate sets a proxy for outputriposte into RisultatoQuestionario.

In the RisultatoQuestionario setter, an inverseAdd method in proxy for outputrisposte is called, and that triggers the load from the database.






Re: Proxy &amp;amp;amp;amp;amp;amp;amp; Lazy Load on Many-To-On Association [message #814420 is a reply to message #814292] Tue, 06 March 2012 12:29 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5332
Registered: July 2009
Senior Member
But the association is not bidirectional is it? Hmm, why the inverseadd?

gr. Martin

On 03/06/2012 10:22 AM, Missing name Mising name wrote:
> maybe i should have opened a new thread, since my current problem is not exatly related to what i described previosuly
> in the thread.
>
> right now, entities are not lazy loaded but eagerly loaded.
>
> RisulatoQuestionario in the model has a one way 1-1 relation with Outputrisposte
>
> the mapping generated is the one in my previous post. The problem is whenever i load 1 risultatoquestonario,
> outputrisposte is loaded as well. Debugging throught the code,
> i tracked down the moment the outputrisposte is loaded.
>
> When RisultatoQuestionario is materialized, hibernate sets a proxy for outputriposte into RisultatoQuestionario.
>
> In the RisultatoQuestionario setter, an inverseAdd method in proxy for outputrisposte is called, and that triggers the
> load from the database.
>
>
>
>
>
>
>


--

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: Proxy &amp;amp;amp;amp;amp;amp;amp; Lazy Load on Many-To-On Association [message #814497 is a reply to message #814420] Tue, 06 March 2012 14:16 Go to previous messageGo to next message
Cristian Prevedello is currently offline Cristian Prevedello
Messages: 33
Registered: June 2011
Member
this is the generated setter code

public void setRisposte(OutputRisposte newRisposte)
	{
		if (newRisposte != risposte)
		{
			NotificationChain msgs = null;
			if (risposte != null)
				msgs = ((InternalEObject)risposte).eInverseRemove(this, ViewshapemodelPackage.OUTPUT_RISPOSTE__RISULTATO_QUESTIONARIO, OutputRisposte.class, msgs);
			if (newRisposte != null)
				msgs = ((InternalEObject)newRisposte).eInverseAdd(this, ViewshapemodelPackage.OUTPUT_RISPOSTE__RISULTATO_QUESTIONARIO, OutputRisposte.class, msgs);
			msgs = basicSetRisposte(newRisposte, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ViewshapemodelPackage.RISULTATI_QUESTIONARIO__RISPOSTE, newRisposte, newRisposte));
	}


anyway you gave an idea, i will try to make the relation bidiretional to see if it works.
Re: Proxy &amp;amp;amp;amp;amp;amp;amp;amp; Lazy Load on Many-To-On Association [message #814526 is a reply to message #814497] Tue, 06 March 2012 14:58 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5332
Registered: July 2009
Senior Member
Hi,
I mean the generated code seems to indicate that it is already bidirectional, which explains the inverseAdd. I mean only
bi-directional associations would have that.
I would say that you should not set it to bi-directional to prevent proxy loading.

gr. Martin

On 03/06/2012 03:16 PM, Missing name Mising name wrote:
> this is the generated setter code
>
>
> public void setRisposte(OutputRisposte newRisposte)
> {
> if (newRisposte != risposte)
> {
> NotificationChain msgs = null;
> if (risposte != null)
> msgs = ((InternalEObject)risposte).eInverseRemove(this, ViewshapemodelPackage.OUTPUT_RISPOSTE__RISULTATO_QUESTIONARIO,
> OutputRisposte.class, msgs);
> if (newRisposte != null)
> msgs = ((InternalEObject)newRisposte).eInverseAdd(this, ViewshapemodelPackage.OUTPUT_RISPOSTE__RISULTATO_QUESTIONARIO,
> OutputRisposte.class, msgs);
> msgs = basicSetRisposte(newRisposte, msgs);
> if (msgs != null) msgs.dispatch();
> }
> else if (eNotificationRequired())
> eNotify(new ENotificationImpl(this, Notification.SET, ViewshapemodelPackage.RISULTATI_QUESTIONARIO__RISPOSTE,
> newRisposte, newRisposte));
> }
>
>
> anyway you gave an idea, i will try to make the relation bidiretional to see if it works.


--

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: Proxy &amp;amp;amp;amp;amp;amp;amp; Lazy Load on Many-To-On Association [message #814534 is a reply to message #814497] Tue, 06 March 2012 15:09 Go to previous messageGo to next message
Cristian Prevedello is currently offline Cristian Prevedello
Messages: 33
Registered: June 2011
Member
hmm, is there some place where i set the type of the relationship?

So far i thought a relationship was unidirectional if i had only one link from an entity (A) to another (B)

if i create another link from B to A and i set it as opposite to first one then the relationship is bidirectional, or am i wrong?
Re: Proxy &amp;amp;amp;amp;amp;amp;amp;amp; Lazy Load on Many-To-On Association [message #814583 is a reply to message #814534] Tue, 06 March 2012 16:19 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5332
Registered: July 2009
Senior Member
Yes only if there is an opposite set then it is bidirectional, are you sure that the generated code is not accidentally
based on a version with a bi-directional association?

gr. Martin

On 03/06/2012 04:09 PM, Missing name Mising name wrote:
> hmm, is there some place where i set the type of the relationship?
> So far i thought a relationship was unidirectional if i had only one link from an entity (A) to another (B)
>
> if i create another link from B to A and i set it as opposite to first one then the relationship is bidirectional, or am
> i wrong?


--

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: Proxy &amp;amp;amp;amp;amp;amp;amp;amp; Lazy Load on Many-To-On Association [message #815928 is a reply to message #814583] Thu, 08 March 2012 08:04 Go to previous message
Cristian Prevedello is currently offline Cristian Prevedello
Messages: 33
Registered: June 2011
Member
Well, yes the model always had an unidirectional relationship between the two entities. anyway creating the opposite relationship, and setting mappedby on the @OneToOne annotation fixed the problem.

I'll investigate with more detail as soon as i've some spare time, since in my model i've some others one-to-one entities, and from a first sight some entities lazy loading works out of the box.

ty
Previous Topic:org.eclipse.emf.ocl
Next Topic:generate ecore from xsd with multiple epackages in the root?
Goto Forum:
  


Current Time: Tue Sep 16 19:37:28 GMT 2014

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

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