Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Teneo] Lazy ManyToOne
[Teneo] Lazy ManyToOne [message #534996] Thu, 20 May 2010 23:27 Go to next message
Lemao  is currently offline Lemao Friend
Messages: 48
Registered: December 2009
Member
The Teneo documentation ( http://wiki.eclipse.org/Teneo/Hibernate/EMF_Hibernate_Integr ation_Details#Lazy_loading.2Ffetching.2C_Proxy) mentions explicitly that cglib proxying is supported. Does that mean that javaassist is not supported?

This may be more of a Hibernate question, but in any case I dont understand why a lazy ManyToOne class needs to be explicitly instrumented at build time when EMF model already separates interfaces from implementations.

Re: [Teneo] Lazy ManyToOne [message #535013 is a reply to message #534996] Fri, 21 May 2010 04:47 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Lemao,
Afaik javaassist works just fine. To get proxying working you have to set this property to true:
PersistenceOptions.SET_PROXY

So afaik you don't need instrumentation.

gr. Martin

Lemao wrote:
> The Teneo documentation
> ( http://wiki.eclipse.org/Teneo/Hibernate/EMF_Hibernate_Integr ation_Details#Lazy_loading.2Ffetching.2C_Proxy)
> mentions explicitly that cglib proxying is supported. Does that mean
> that javaassist is not supported?
>
> This may be more of a Hibernate question, but in any case I dont
> understand why a lazy ManyToOne class needs to be explicitly
> instrumented at build time when EMF model already separates interfaces
> from implementations.
>
>


--

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 ManyToOne [message #535258 is a reply to message #535013] Fri, 21 May 2010 18:34 Go to previous messageGo to next message
Lemao  is currently offline Lemao Friend
Messages: 48
Registered: December 2009
Member
Humm, interesting... that's what I would expect: no need for instrumentation. I understand that lazy properties do require instrumentation but was expecting ManyToOne proxying to work out of the box. Teneo PROXY setting is set to true and my ManyToOne reference is optional.

I basically have a Submission--many-to-one-->Content (i.e. multiple submissions sharing the same content blob) and I would like to be able to use EntityManager.getReference() to create additional Submission's without having to actually load the Content (I know the id). But what I am seeing is getReference() turn into a get(). After some debugging it comes down the hibernate EntityMetadata.lazy being false because there was no instrumentation.

thanks,
-- yuri
Re: [Teneo] Lazy ManyToOne [message #535276 is a reply to message #535258] Fri, 21 May 2010 19:00 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Can you check the generated mapping (dataStore.getMappingXML()) to check if the class has indeed proxy set to true and
also that the many-to-one is mapped with the lazy attribute?

gr. Martin

Lemao wrote:
> Humm, interesting... that's what I would expect: no need for
> instrumentation. I understand that lazy properties do require
> instrumentation but was expecting ManyToOne proxying to work out of the
> box. Teneo PROXY setting is set to true and my ManyToOne reference is
> optional.
>
> I basically have a Submission--many-to-one-->Content (i.e. multiple
> submissions sharing the same content blob) and I would like to be able
> to use EntityManager.getReference() to create additional Submission's
> without having to actually load the Content (I know the id). But what I
> am seeing is getReference() turn into a get(). After some debugging it
> comes down the hibernate EntityMetadata.lazy being false because there
> was no instrumentation.
>
> thanks,
> -- yuri


--

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 ManyToOne [message #535286 is a reply to message #534996] Fri, 21 May 2010 21:30 Go to previous messageGo to next message
Lemao  is currently offline Lemao Friend
Messages: 48
Registered: December 2009
Member
Most interesting... My @ManyToOne(fetch=LAZY) ends up as lazy=false in Hibernate. The reason is that Hibernate is setting lazy to true only when the lazy attribute value is true (lazy="true"), but the schema only allows false, proxy or no-proxy so it will never be true.

This is from Hibernate sources:
		boolean isLazyable = "property".equals( node.getName() ) ||
				"component".equals( node.getName() ) ||
				"many-to-one".equals( node.getName() ) ||
				"one-to-one".equals( node.getName() ) ||
				"any".equals( node.getName() );
		if ( isLazyable ) {
			Attribute lazyNode = node.attribute( "lazy" );
			property.setLazy( lazyNode != null && "true".equals( lazyNode.getValue() ) );
		}


From a distance this seems to be a bug. Am I missing something here? I looked into the latest 3.5.1-Final and the same code is there.

[INFO] +- org.hibernate:hibernate-entitymanager:jar:3.4.0.GA:compile
[INFO] |  +- org.hibernate:ejb3-persistence:jar:1.0.2.GA:compile
[INFO] |  +- org.hibernate:hibernate-commons-annotations:jar:3.1.0.GA:compile
[INFO] |  +- org.hibernate:hibernate-annotations:jar:3.4.0.GA:compile
[INFO] |  \- javassist:javassist:jar:3.4.GA:compile
[INFO] +- cglib:cglib:jar:2.2:compile
[INFO] |  \- asm:asm:jar:3.1:compile


Re: [Teneo] Lazy ManyToOne [message #535305 is a reply to message #534996] Fri, 21 May 2010 23:43 Go to previous messageGo to next message
Lemao  is currently offline Lemao Friend
Messages: 48
Registered: December 2009
Member
Martin,

I made some progress here. The lazy loading issue seems to come down to Resolve Proxies set to true in my ManyToOne reference. The getXXX() was called, EMF was calling eIsProxy() on the javassist proxy which was triggering the load.

Once I turned that off the lazy loading worked.

[Updated on: Fri, 21 May 2010 23:53]

Report message to a moderator

Re: [Teneo] Lazy ManyToOne [message #535310 is a reply to message #535305] Sat, 22 May 2010 04:37 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Good that it works now! I have added your other reply (hibernate.ejb.metamodel.generation=disabled) to the faq:
http://wiki.eclipse.org/Teneo/Hibernate/FAQ#Mapping_Exceptio n_Unknown_Entity

gr. Martin

Lemao wrote:
> Martin,
> I made some progress here. The lazy loading issue seems to come down to
> Resolve Proxies set to true in my ManyToOne reference. The getXXX() was
> called, EMF was calling eIsProxy() on the javassist proxy which was
> triggering the load.
>
> Once I turned that off the lazy loading worked.
>
> thanks,
> -- yuri
>


--

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 ManyToOne [message #535351 is a reply to message #534996] Sat, 22 May 2010 16:41 Go to previous messageGo to next message
Lemao  is currently offline Lemao Friend
Messages: 48
Registered: December 2009
Member
Hi Martin,

Just one comment: dont think it fixes the getReference(), get() calls, only when trying to use Teneo/JPA with the latest Hibernate 3.5.1-Final.

I also came across another issue. Calling getId() on a proxy object trigger a database select even though the id is local to the proxy. After some investigation, it turns out that the persistentClass in hibernate has null idSetter/idGetter because the EAttributePropertyHandler.getMethod() always returns null.
Re: [Teneo] Lazy ManyToOne [message #535650 is a reply to message #535351] Tue, 25 May 2010 07:00 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Lemao,
Yes the EAttributePropertyHandler is also used for DynamicEMF, therefore no get method is returned.

You can also put the getId logic in a utility method and then cast the object to a HibernateProxy (if it is this) and
get the id from the HibernateProxy without initialization:
if (o instanceof HibernateProxy) {
return ((HibernateProxy) o).getHibernateLazyInitializer().getIdentifier();
}
and the class like this:
((HibernateProxy) o).getHibernateLazyInitializer().getPersistentClass()

gr. Martin

Lemao wrote:
> Hi Martin,
> Just one comment: dont think it fixes the getReference(), get() calls,
> only when trying to use Teneo/JPA with the latest Hibernate 3.5.1-Final.
>
> I also came across another issue. Calling getId() on a proxy object
> trigger a database select even though the id is local to the proxy.
> After some investigation, it turns out that the persistentClass in
> hibernate has null idSetter/idGetter because the
> EAttributePropertyHandler.getMethod() always returns null.


--

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
Previous Topic:[CDO Hibernate Store] NonUniqueObjectException when saving model with bidirectional references (bug?
Next Topic:Editor Unloading, Concurrency and Persistence
Goto Forum:
  


Current Time: Fri Apr 19 06:48:25 GMT 2024

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

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

Back to the top