Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Teneo] hibernate collection lazy loading behavior ?
[Teneo] hibernate collection lazy loading behavior ? [message #425641] Wed, 03 December 2008 15:51 Go to next message
Stéphane  ournier is currently offline Stéphane ournierFriend
Messages: 304
Registered: July 2009
Senior Member
Hi,

To continue from the previous post (see
http://www.eclipse.org/newsportal/article.php?id=37502&g roup=eclipse.tools.emf#37502),
I failed to load collections lazily. :(

I tried with the very simple Library model with 3 classes : Library, Book,
Writer to avoid FeatureMap collections, Library that contains other ones
and so on...

I create a root library with a book and its writer.

Here the cfg parameters, I use to initialize the HbDataStore (sorry for
the code format due to copy/paste in the newsportal) :

final Properties props = new Properties();
props.setProperty(Environment.DRIVER, "com.mysql.jdbc.Driver");
props.setProperty(Environment.USER, "lacarotte");
props.setProperty(Environment.URL,
"jdbc:mysql://localhost:3306/testOldLibrary");
props.setProperty(Environment.PASS, "lcelb");
props.setProperty(Environment.DIALECT,
org.hibernate.dialect.MySQLInnoDBDialect.class.getName());
props.setProperty(Environment.HBM2DDL_AUTO, "update");
props.setProperty(Environment.SHOW_SQL, Boolean.TRUE.toString());
props.setProperty(Environment.FORMAT_SQL, Boolean.TRUE.toString());
props.setProperty(Environment.DEFAULT_BATCH_FETCH_SIZE, "10");
props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
props.setProperty(PersistenceOptions.DEFAULT_CACHE_STRATEGY, "NONE");
props.setProperty(PersistenceOptions.SET_PROXY,
Boolean.TRUE.toString());

// Initialize create the HbDataStore
HbDataStore hbds =
HbHelper.INSTANCE.createRegisterDataStore("library");

hbds.setEPackages(new EPackage[] { LibraryPackage.eINSTANCE });
hbds.setProperties(props);
hbds.initialize();

The resource is loaded with topClassesBehavior that runs a query ("from
library").
I debugged the query execution that returns the root library with its
children.
At that point, lazy loading failed.
The code that loads the children is located in
TwoPhaseLoad#initializeEntity(..) (called by
QueryLoader#initializeEntitiesAndCollections):
Object[] hydratedState = entityEntry.getLoadedState();

if ( log.isDebugEnabled() )
log.debug("resolving associations for " +
MessageHelper.infoString(persister, id, session.getFactory()));
Type[] types = persister.getPropertyTypes();
for ( int i = 0; i < hydratedState.length; i++ ) {
final Object value = hydratedState[i];
if ( value!=LazyPropertyInitializer.UNFETCHED_PROPERTY &&
value!=BackrefPropertyAccessor.UNKNOWN ) {
hydratedState[i] = types[i].resolve( value, session, entity );
}
}
...

The hydratedState array corresponds to my root library. This one contains
2 MarkerObject instances set to NOT_NULL_COLLECTION regarding the 'books'
and the 'writers' collections.
The call to types[i].resolve( value, session, entity ) when types[i] is
such a MarkerObject resolves it as a PersistentList with its data.

I would expect a new MarkerObject set to UNFECTCHED_COLLECTION or a not
loaded PersistentList (i.e a lazy one).

Here is a copy, of the generated hibernate mapping where data are
collections are well tagged as lazy ones.

Help would be appreciated.
Stephane.


Mapping content :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD
3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping auto-import="false">
<class name="org.eclipse.example.library.impl.BookImpl"
entity-name="Book" abstract="false" lazy="true" table="`book`"
proxy="org.eclipse.example.library.Book">
<meta attribute="eclassName">Book</meta>
<meta
attribute="epackage">http:///org/eclipse/example/library.ecore</meta>
<id type="long" name="e_id" column="e_id"
access=" org.eclipse.emf.teneo.hibernate.mapping.identifier.Identifie rPropertyHandler ">
<meta attribute="syntheticId">true</meta>
<generator class="native"/>
</id>
<version name="e_version" column="e_version"
access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHandler ">
<meta attribute="syntheticVersion">true</meta>
</version>
<property name="title" lazy="false" insert="true" update="true"
not-null="false" unique="false" type="java.lang.String">
<column not-null="false" unique="false" name="`title`"/>
</property>
<property name="pages" lazy="false" insert="true" update="true"
not-null="false" unique="false" type="int">
<column not-null="false" unique="false" name="`pages`"/>
</property>
<property name="category" lazy="false" not-null="false" insert="true"
update="true" unique="false">
<column not-null="false" unique="false" name="`category`"/>
<type name="org.eclipse.emf.teneo.hibernate.mapping.ENumUserType" >
<param
name="enumClass">org.eclipse.example.library.BookCategory</param >
</type>
</property>
<many-to-one name="author" entity-name="Writer" lazy="proxy"
foreign-key="book_author" insert="true" update="true" not-null="false">
<column not-null="false" unique="false" name="`book_author_e_id`"/>
</many-to-one>
</class>
<class name="org.eclipse.example.library.impl.LibraryImpl"
entity-name="Library" abstract="false" lazy="true" table="`library`"
proxy="org.eclipse.example.library.Library">
<meta attribute="eclassName">Library</meta>
<meta
attribute="epackage">http:///org/eclipse/example/library.ecore</meta>
<id type="long" name="e_id" column="e_id"
access=" org.eclipse.emf.teneo.hibernate.mapping.identifier.Identifie rPropertyHandler ">
<meta attribute="syntheticId">true</meta>
<generator class="native"/>
</id>
<version name="e_version" column="e_version"
access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHandler ">
<meta attribute="syntheticVersion">true</meta>
</version>
<property name="name" lazy="false" insert="true" update="true"
not-null="false" unique="false" type="java.lang.String">
<column not-null="false" unique="false" name="`name`"/>
</property>
<list name="writers" lazy="true" cascade="all,delete-orphan">
<key update="true" foreign-key="library_writers">
<column name="`library_writers_e_id`" not-null="false" unique="false"/>
</key>
<list-index column="`library_writers_idx`"/>
<one-to-many entity-name="Writer"/>
</list>
<list name="books" lazy="true" cascade="all,delete-orphan">
<key update="true" foreign-key="library_books">
<column name="`library_books_e_id`" not-null="false" unique="false"/>
</key>
<list-index column="`library_books_idx`"/>
<one-to-many entity-name="Book"/>
</list>
</class>
<class name="org.eclipse.example.library.impl.WriterImpl"
entity-name="Writer" abstract="false" lazy="true" table="`writer`"
proxy="org.eclipse.example.library.Writer">
<meta attribute="eclassName">Writer</meta>
<meta
attribute="epackage">http:///org/eclipse/example/library.ecore</meta>
<id type="long" name="e_id" column="e_id"
access=" org.eclipse.emf.teneo.hibernate.mapping.identifier.Identifie rPropertyHandler ">
<meta attribute="syntheticId">true</meta>
<generator class="native"/>
</id>
<version name="e_version" column="e_version"
access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHandler ">
<meta attribute="syntheticVersion">true</meta>
</version>
<property name="name" lazy="false" insert="true" update="true"
not-null="false" unique="false" type="java.lang.String">
<column not-null="false" unique="false" name="`name`"/>
</property>
<list name="books" table="`writer_books`" lazy="true">
<key update="true">
<column name="`writer_e_id`" not-null="true" unique="false"/>
</key>
<list-index column="`writer_books_idx`"/>
<many-to-many entity-name="Book" unique="true">
<column name="`book_e_id`" not-null="true" unique="false"/>
</many-to-many>
</list>
</class>
</hibernate-mapping>
Re: [Teneo] hibernate collection lazy loading behavior ? [message #425658 is a reply to message #425641] Wed, 03 December 2008 22:47 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Stéphane,
I tested this and with me it worked fine.

This is for example the mapping for the library.books:
<list name="books" lazy="true" cascade="all,delete-orphan">
<key update="true" foreign-key="library_books">
<column name="`library_books_e_id`" not-null="false" unique="false"/>
</key>
<list-index column="`library_books_idx`"/>
<one-to-many entity-name="Book"/>
</list>

and when I get the library it is not loaded:
Library lib = (Library) res.getContents().get(0);
only when I do this (in the testcase), the books get loaded:
assertEquals(3, lib.getBooks().size());

Some info, an unloaded Hibernate persistentlist has a list member with value null, if it is loaded
there will be an arraylist in there.

With you the list member of the hibernate persistentlist is set?

gr. Martin


Stéphane Fournier wrote:
> Hi,
> To continue from the previous post (see
> http://www.eclipse.org/newsportal/article.php?id=37502&g roup=eclipse.tools.emf#37502),
> I failed to load collections lazily. :(
>
> I tried with the very simple Library model with 3 classes : Lib
rary,
> Book, Writer to avoid FeatureMap collections, Library that contains
> other ones and so on...
>
> I create a root library with a book and its writer.
>
> Here the cfg parameters, I use to initialize the HbDataStore (sorry for
> the code format due to copy/paste in the newsportal) :
>
> final Properties props = new Properties();
> props.setProperty(Environment.DRIVER, "com.mysql.jdbc.Driver");
> props.setProperty(Environment.USER, "lacarotte");
> props.setProperty(Environment.URL,
> "jdbc:mysql://localhost:3306/testOldLibrary");
> props.setProperty(Environment.PASS, "lcelb");
> props.setProperty(Environment.DIALECT,
> org.hibernate.dialect.MySQLInnoDBDialect.class.getName());
> props.setProperty(Environment.HBM2DDL_AUTO, "update");
> props.setProperty(Environment.SHOW_SQL, Boolean.TRUE.toString());
> props.setProperty(Environment.FORMAT_SQL, Boolean.TRUE.toString());
> props.setProperty(Environment.DEFAULT_BATCH_FETCH_SIZE, "10");
> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
> props.setProperty(PersistenceOptions.DEFAULT_CACHE_STRATEGY, "NONE");
> props.setProperty(PersistenceOptions.SET_PROXY,
> Boolean.TRUE.toString());
>
> // Initialize create the HbDataStore
> HbDataStore hbds =
> HbHelper.INSTANCE.createRegisterDataStore("library");
>
> hbds.setEPackages(new EPackage[] { LibraryPackage.eINSTANCE });
> hbds.setProperties(props);
> hbds.initialize();
>
> The resource is loaded with topClassesBehavior that runs a query ("from
> library").
> I debugged the query execution that returns the root library with its
> children.
> At that point, lazy loading failed.
> The code that loads the children is located in
> TwoPhaseLoad#initializeEntity(..) (called by
> QueryLoader#initializeEntitiesAndCollections):
> Object[] hydratedState = entityEntry.getLoadedState();
>
> if ( log.isDebugEnabled() )
> log.debug("resolving associations for " +
> MessageHelper.infoString(persister, id, session.getFactory()));
> Type[] types = persister.getPropertyTypes();
> for ( int i = 0; i < hydratedState.length; i++ ) {
> final Object value = hydratedState[i];
> if ( value!=LazyPropertyInitializer.UNFETCHED_PROPERTY &&
> value!=BackrefPropertyAccessor.UNKNOWN ) {
> hydratedState[i] = types[i].resolve( value, session, entity );
> }
> }
> ...
>
> The hydratedState array corresponds to my root library. This one
> contains 2 MarkerObject instances set to NOT_NULL_COLLECTION regarding
> the 'books' and the 'writers' collections.
> The call to types[i].resolve( value, session, entity ) when types[i] is
> such a MarkerObject resolves it as a PersistentList with its data.
>
> I would expect a new MarkerObject set to UNFECTCHED_COLLECTION or a not
> loaded PersistentList (i.e a lazy one).
>
> Here is a copy, of the generated hibernate mapping where data are
> collections are well tagged as lazy ones.
>
> Help would be appreciated.
> Stephane.
>
>
> Mapping content :
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD
> 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
>
> <hibernate-mapping auto-import="false">
> <class name="org.eclipse.example.library.impl.BookImpl"
> entity-name="Book" abstract="false" lazy="true" table="`book`"
> proxy="org.eclipse.example.library.Book">
> <meta attribute="eclassName">Book</meta>
> <meta
> attribute="epackage">http:///org/eclipse/example/library.ecore</meta>
> <id type="long" name="e_id" column="e_id"
> access=" org.eclipse.emf.teneo.hibernate.mapping.identifier.Identifie rPropertyHandler ">
>
> <meta attribute="syntheticId">true</meta>
> <generator class="native"/>
> </id>
> <version name="e_version" column="e_version"
> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHandler ">
>
> <meta attribute="syntheticVersion">true</meta>
> </version>
> <property name="title" lazy="false" insert="true" update="true"
> not-null="false" unique="false" type="java.lang.String">
> <column not-null="false" unique="false" name="`title`"/>
> </property>
> <property name="pages" lazy="false" insert="true" update="true"
> not-null="false" unique="false" type="int">
> <column not-null="false" unique="false" name="`pages`"/>
> </property>
> <property name="category" lazy="false" not-null="false"
> insert="true" update="true" unique="false">
> <column not-null="false" unique="false" name="`category`"/>
> <type
> name="org.eclipse.emf.teneo.hibernate.mapping.ENumUserType" >
> <param
> name="enumClass">org.eclipse.example.library.BookCategory</param >
> </type>
> </property>
> <many-to-one name="author" entity-name="Writer" lazy="proxy"
> foreign-key="book_author" insert="true" update="true" not-null="false">
> <column not-null="false" unique="false"
> name="`book_author_e_id`"/>
> </many-to-one>
> </class>
> <class name="org.eclipse.example.library.impl.LibraryImpl"
> entity-name="Library" abstract="false" lazy="true" table="`library`"
> proxy="org.eclipse.example.library.Library">
> <meta attribute="eclassName">Library</meta>
> <meta
> attribute="epackage">http:///org/eclipse/example/library.ecore</meta>
> <id type="long" name="e_id" column="e_id"
> access=" org.eclipse.emf.teneo.hibernate.mapping.identifier.Identifie rPropertyHandler ">
>
> <meta attribute="syntheticId">true</meta>
> <generator class="native"/>
> </id>
> <version name="e_version" column="e_version"
> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHandler ">
>
> <meta attribute="syntheticVersion">true</meta>
> </version>
> <property name="name" lazy="false" insert="true" update="true"
> not-null="false" unique="false" type="java.lang.String">
> <column not-null="false" unique="false" name="`name`"/>
> </property>
> <list name="writers" lazy="true" cascade="all,delete-orphan">
> <key update="true" foreign-key="library_writers">
> <column name="`library_writers_e_id`" not-null="false"
> unique="false"/>
> </key>
> <list-index column="`library_writers_idx`"/>
> <one-to-many entity-name="Writer"/>
> </list>
> <list name="books" lazy="true" cascade="all,delete-orphan">
> <key update="true" foreign-key="library_books">
> <column name="`library_books_e_id`" not-null="false"
> unique="false"/>
> </key>
> <list-index column="`library_books_idx`"/>
> <one-to-many entity-name="Book"/>
> </list>
> </class>
> <class name="org.eclipse.example.library.impl.WriterImpl"
> entity-name="Writer" abstract="false" lazy="true" table="`writer`"
> proxy="org.eclipse.example.library.Writer">
> <meta attribute="eclassName">Writer</meta>
> <meta
> attribute="epackage">http:///org/eclipse/example/library.ecore</meta>
> <id type="long" name="e_id" column="e_id"
> access=" org.eclipse.emf.teneo.hibernate.mapping.identifier.Identifie rPropertyHandler ">
>
> <meta attribute="syntheticId">true</meta>
> <generator class="native"/>
> </id>
> <version name="e_version" column="e_version"
> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHandler ">
>
> <meta attribute="syntheticVersion">true</meta>
> </version>
> <property name="name" lazy="false" insert="true" update="true"
> not-null="false" unique="false" type="java.lang.String">
> <column not-null="false" unique="false" name="`name`"/>
> </property>
> <list name="books" table="`writer_books`" lazy="true">
> <key update="true">
> <column name="`writer_e_id`" not-null="true"
> unique="false"/>
> </key>
> <list-index column="`writer_books_idx`"/>
> <many-to-many entity-name="Book" unique="true">
> <column name="`book_e_id`" not-null="true" unique="false"/>
> </many-to-many>
> </list>
> </class>
> </hibernate-mapping>
>
>
>
>
>
>
>
>


--

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] hibernate collection lazy loading behavior ? [message #425681 is a reply to message #425658] Thu, 04 December 2008 15:32 Go to previous messageGo to next message
Guillaume Brocard is currently offline Guillaume BrocardFriend
Messages: 25
Registered: July 2009
Junior Member
Hi Martin,

I'm working with Stéphane on this, and since he can't answer right now,
I'm taking up the torch.

I have conducted the very same test with the extended library model (the
one with feature map), and basically, the objects stored in the database
are looking like the following tree :

Library demo
Library NoName
Book book1
Writer writer2
Borrower borrower3
Library library4
Library library5
Book book6
...
...
Borrower borrower9999
Book book10000

So objects are being possessed through libraries, using either the
Library.stock, Library.people, or Library.branches containment
relationships.

We are using a HibernateResource, with initial query set to :
"SELECT library FROM Library library WHERE library.name='demo'"

As I debug the loading of my resource (
HibernateResource.loadUsingDefinedQueries(SessionWrapper sess); line 500) :
final List<?> qryResult = sess.executeQuery(element);
the resulting list does contain Library Demo.

Unfortunately, its branches list is initialized with Library NoName, which
in turn is initialized with book1, writer2, ..., library4, ... book10000
all resolved.

As Stéphane said, that has to do with the hydrated states of the objects
(see Stéphane's explanations).
What are we missing here ?

Thanks in advance,
Guillaume.


Martin Taal wrote:

> Hi Stéphane,
> I tested this and with me it worked fine.

> This is for example the mapping for the library.books:
> <list name="books" lazy="true" cascade="all,delete-orphan">
> <key update="true" foreign-key="library_books">
> <column name="`library_books_e_id`" not-null="false" unique="false"/>
> </key>
> <list-index column="`library_books_idx`"/>
> <one-to-many entity-name="Book"/>
> </list>

> and when I get the library it is not loaded:
> Library lib = (Library) res.getContents().get(0);
> only when I do this (in the testcase), the books get loaded:
> assertEquals(3, lib.getBooks().size());

> Some info, an unloaded Hibernate persistentlist has a list member with value
null, if it is loaded
> there will be an arraylist in there.

> With you the list member of the hibernate persistentlist is set?

> gr. Martin


> Stéphane Fournier wrote:
>> Hi,
>> To continue from the previous post (see
>>
http://www.eclipse.org/newsportal/article.php?id=37502&g roup=eclipse.tools.emf#37502),
>> I failed to load collections lazily. :(
>>
>> I tried with the very simple Library model with 3 classes : Lib
> rary,
>> Book, Writer to avoid FeatureMap collections, Library that contains
>> other ones and so on...
>>
>> I create a root library with a book and its writer.
>>
>> Here the cfg parameters, I use to initialize the HbDataStore (sorry for
>> the code format due to copy/paste in the newsportal) :
>>
>> final Properties props = new Properties();
>> props.setProperty(Environment.DRIVER, "com.mysql.jdbc.Driver");
>> props.setProperty(Environment.USER, "lacarotte");
>> props.setProperty(Environment.URL,
>> "jdbc:mysql://localhost:3306/testOldLibrary");
>> props.setProperty(Environment.PASS, "lcelb");
>> props.setProperty(Environment.DIALECT,
>> org.hibernate.dialect.MySQLInnoDBDialect.class.getName());
>> props.setProperty(Environment.HBM2DDL_AUTO, "update");
>> props.setProperty(Environment.SHOW_SQL, Boolean.TRUE.toString());
>> props.setProperty(Environment.FORMAT_SQL, Boolean.TRUE.toString());
>> props.setProperty(Environment.DEFAULT_BATCH_FETCH_SIZE, "10");
>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>> props.setProperty(PersistenceOptions.DEFAULT_CACHE_STRATEGY, "NONE");
>> props.setProperty(PersistenceOptions.SET_PROXY,
>> Boolean.TRUE.toString());
>>
>> // Initialize create the HbDataStore
>> HbDataStore hbds =
>> HbHelper.INSTANCE.createRegisterDataStore("library");
>>
>> hbds.setEPackages(new EPackage[] { LibraryPackage.eINSTANCE });
>> hbds.setProperties(props);
>> hbds.initialize();
>>
>> The resource is loaded with topClassesBehavior that runs a query ("from
>> library").
>> I debugged the query execution that returns the root library with its
>> children.
>> At that point, lazy loading failed.
>> The code that loads the children is located in
>> TwoPhaseLoad#initializeEntity(..) (called by
>> QueryLoader#initializeEntitiesAndCollections):
>> Object[] hydratedState = entityEntry.getLoadedState();
>>
>> if ( log.isDebugEnabled() )
>> log.debug("resolving associations for " +
>> MessageHelper.infoString(persister, id, session.getFactory()));
>> Type[] types = persister.getPropertyTypes();
>> for ( int i = 0; i < hydratedState.length; i++ ) {
>> final Object value = hydratedState[i];
>> if ( value!=LazyPropertyInitializer.UNFETCHED_PROPERTY &&
>> value!=BackrefPropertyAccessor.UNKNOWN ) {
>> hydratedState[i] = types[i].resolve( value, session, entity );
>> }
>> }
>> ...
>>
>> The hydratedState array corresponds to my root library. This one
>> contains 2 MarkerObject instances set to NOT_NULL_COLLECTION regarding
>> the 'books' and the 'writers' collections.
>> The call to types[i].resolve( value, session, entity ) when types[i] is
>> such a MarkerObject resolves it as a PersistentList with its data.
>>
>> I would expect a new MarkerObject set to UNFECTCHED_COLLECTION or a not
>> loaded PersistentList (i.e a lazy one).
>>
>> Here is a copy, of the generated hibernate mapping where data are
>> collections are well tagged as lazy ones.
>>
>> Help would be appreciated.
>> Stephane.
>>
>>
>> Mapping content :
>> <?xml version="1.0" encoding="UTF-8"?>
>> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD
>> 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
>>
>> <hibernate-mapping auto-import="false">
>> <class name="org.eclipse.example.library.impl.BookImpl"
>> entity-name="Book" abstract="false" lazy="true" table="`book`"
>> proxy="org.eclipse.example.library.Book">
>> <meta attribute="eclassName">Book</meta>
>> <meta
>> attribute="epackage">http:///org/eclipse/example/library.ecore</meta>
>> <id type="long" name="e_id" column="e_id"
>>
access=" org.eclipse.emf.teneo.hibernate.mapping.identifier.Identifie rPropertyHandler ">
>>
>> <meta attribute="syntheticId">true</meta>
>> <generator class="native"/>
>> </id>
>> <version name="e_version" column="e_version"
>>
access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHandler ">
>>
>> <meta attribute="syntheticVersion">true</meta>
>> </version>
>> <property name="title" lazy="false" insert="true" update="true"
>> not-null="false" unique="false" type="java.lang.String">
>> <column not-null="false" unique="false" name="`title`"/>
>> </property>
>> <property name="pages" lazy="false" insert="true" update="true"
>> not-null="false" unique="false" type="int">
>> <column not-null="false" unique="false" name="`pages`"/>
>> </property>
>> <property name="category" lazy="false" not-null="false"
>> insert="true" update="true" unique="false">
>> <column not-null="false" unique="false" name="`category`"/>
>> <type
>> name="org.eclipse.emf.teneo.hibernate.mapping.ENumUserType" >
>> <param
>> name="enumClass">org.eclipse.example.library.BookCategory</param >
>> </type>
>> </property>
>> <many-to-one name="author" entity-name="Writer" lazy="proxy"
>> foreign-key="book_author" insert="true" update="true" not-null="false">
>> <column not-null="false" unique="false"
>> name="`book_author_e_id`"/>
>> </many-to-one>
>> </class>
>> <class name="org.eclipse.example.library.impl.LibraryImpl"
>> entity-name="Library" abstract="false" lazy="true" table="`library`"
>> proxy="org.eclipse.example.library.Library">
>> <meta attribute="eclassName">Library</meta>
>> <meta
>> attribute="epackage">http:///org/eclipse/example/library.ecore</meta>
>> <id type="long" name="e_id" column="e_id"
>>
access=" org.eclipse.emf.teneo.hibernate.mapping.identifier.Identifie rPropertyHandler ">
>>
>> <meta attribute="syntheticId">true</meta>
>> <generator class="native"/>
>> </id>
>> <version name="e_version" column="e_version"
>>
access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHandler ">
>>
>> <meta attribute="syntheticVersion">true</meta>
>> </version>
>> <property name="name" lazy="false" insert="true" update="true"
>> not-null="false" unique="false" type="java.lang.String">
>> <column not-null="false" unique="false" name="`name`"/>
>> </property>
>> <list name="writers" lazy="true" cascade="all,delete-orphan">
>> <key update="true" foreign-key="library_writers">
>> <column name="`library_writers_e_id`" not-null="false"
>> unique="false"/>
>> </key>
>> <list-index column="`library_writers_idx`"/>
>> <one-to-many entity-name="Writer"/>
>> </list>
>> <list name="books" lazy="true" cascade="all,delete-orphan">
>> <key update="true" foreign-key="library_books">
>> <column name="`library_books_e_id`" not-null="false"
>> unique="false"/>
>> </key>
>> <list-index column="`library_books_idx`"/>
>> <one-to-many entity-name="Book"/>
>> </list>
>> </class>
>> <class name="org.eclipse.example.library.impl.WriterImpl"
>> entity-name="Writer" abstract="false" lazy="true" table="`writer`"
>> proxy="org.eclipse.example.library.Writer">
>> <meta attribute="eclassName">Writer</meta>
>> <meta
>> attribute="epackage">http:///org/eclipse/example/library.ecore</meta>
>> <id type="long" name="e_id" column="e_id"
>>
access=" org.eclipse.emf.teneo.hibernate.mapping.identifier.Identifie rPropertyHandler ">
>>
>> <meta attribute="syntheticId">true</meta>
>> <generator class="native"/>
>> </id>
>> <version name="e_version" column="e_version"
>>
access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHandler ">
>>
>> <meta attribute="syntheticVersion">true</meta>
>> </version>
>> <property name="name" lazy="false" insert="true" update="true"
>> not-null="false" unique="false" type="java.lang.String">
>> <column not-null="false" unique="false" name="`name`"/>
>> </property>
>> <list name="books" table="`writer_books`" lazy="true">
>> <key update="true">
>> <column name="`writer_e_id`" not-null="true"
>> unique="false"/>
>> </key>
>> <list-index column="`writer_books_idx`"/>
>> <many-to-many entity-name="Book" unique="true">
>> <column name="`book_e_id`" not-null="true" unique="false"/>
>> </many-to-many>
>> </list>
>> </class>
>> </hibernate-mapping>
>>
>>
>>
>>
>>
>>
>>
>>
Re: [Teneo] hibernate collection lazy loading behavior ? [message #425686 is a reply to message #425681] Thu, 04 December 2008 16:41 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Brocard,
Yes I can see what you mean but I would need to debug locally to see what goes on. Can you email me
a test Eclipse project with a database dump (mysql)? Hibernate libs are not needed. Then I can try
myself.

gr. Martin

Brocard Guillaume wrote:
> Hi Martin,
>
> I'm working with Stéphane on this, and since he can't answer right now,
> I'm taking up the torch.
>
> I have conducted the very same test with the extended library model (the
> one with feature map), and basically, the objects stored in the database
> are looking like the following tree :
>
> Library demo
> Library NoName
> Book book1
> Writer writer2
> Borrower borrower3
> Library library4
> Library library5
> Book book6
> ...
> ...
> Borrower borrower9999
> Book book10000
>
> So objects are being possessed through libraries, using either the
> Library.stock, Library.people, or Library.branches containment
> relationships.
>
> We are using a HibernateResource, with initial query set to :
> "SELECT library FROM Library library WHERE library.name='demo'"
>
> As I debug the loading of my resource (
> HibernateResource.loadUsingDefinedQueries(SessionWrapper sess); line 500) :
> final List<?> qryResult = sess.executeQuery(element);
> the resulting list does contain Library Demo.
>
> Unfortunately, its branches list is initialized with Library NoName,
> which in turn is initialized with book1, writer2, ..., library4, ...
> book10000 all resolved.
>
> As Stéphane said, that has to do with the hydrated states of the objects
> (see Stéphane's explanations).
> What are we missing here ?
>
> Thanks in advance,
> Guillaume.
>
>
> Martin Taal wrote:
>
>> Hi Stéphane,
>> I tested this and with me it worked fine.
>
>> This is for example the mapping for the library.books:
>> <list name="books" lazy="true" cascade="all,delete-orphan">
>> <key update="true" foreign-key="library_books">
>> <column name="`library_books_e_id`" not-null="false"
>> unique="false"/>
>> </key>
>> <list-index column="`library_books_idx`"/>
>> <one-to-many entity-name="Book"/>
>> </list>
>
>> and when I get the library it is not loaded:
>> Library lib = (Library) res.getContents().get(0);
>> only when I do this (in the testcase), the books get loaded:
>> assertEquals(3, lib.getBooks().size());
>
>> Some info, an unloaded Hibernate persistentlist has a list member with
>> value
> null, if it is loaded
>> there will be an arraylist in there.
>
>> With you the list member of the hibernate persistentlist is set?
>
>> gr. Martin
>
>
>> Stéphane Fournier wrote:
>>> Hi,
>>> To continue from the previous post (see
> http://www.eclipse.org/newsportal/article.php?id=37502&g roup=eclipse.tools.emf#37502),
>
>>> I failed to load collections lazily. :(
>>>
>>> I tried with the very simple Library model with 3 classes :
>>> Lib
>> rary,
>>> Book, Writer to avoid FeatureMap collections, Library that contains
>>> other ones and so on...
>>>
>>> I create a root library with a book and its writer.
>>>
>>> Here the cfg parameters, I use to initialize the HbDataStore (sorry
>>> for the code format due to copy/paste in the newsportal) :
>>>
>>> final Properties props = new Properties();
>>> props.setProperty(Environment.DRIVER, "com.mysql.jdbc.Driver");
>>> props.setProperty(Environment.USER, "lacarotte");
>>> props.setProperty(Environment.URL,
>>> "jdbc:mysql://localhost:3306/testOldLibrary");
>>> props.setProperty(Environment.PASS, "lcelb");
>>> props.setProperty(Environment.DIALECT,
>>> org.hibernate.dialect.MySQLInnoDBDialect.class.getName());
>>> props.setProperty(Environment.HBM2DDL_AUTO, "update");
>>> props.setProperty(Environment.SHOW_SQL, Boolean.TRUE.toString());
>>> props.setProperty(Environment.FORMAT_SQL, Boolean.TRUE.toString());
>>> props.setProperty(Environment.DEFAULT_BATCH_FETCH_SIZE, "10");
>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING,
>>> "JOINED");
>>> props.setProperty(PersistenceOptions.DEFAULT_CACHE_STRATEGY,
>>> "NONE");
>>> props.setProperty(PersistenceOptions.SET_PROXY,
>>> Boolean.TRUE.toString());
>>>
>>> // Initialize create the HbDataStore
>>> HbDataStore hbds =
>>> HbHelper.INSTANCE.createRegisterDataStore("library");
>>>
>>> hbds.setEPackages(new EPackage[] { LibraryPackage.eINSTANCE });
>>> hbds.setProperties(props);
>>> hbds.initialize();
>>>
>>> The resource is loaded with topClassesBehavior that runs a query
>>> ("from library").
>>> I debugged the query execution that returns the root library with its
>>> children.
>>> At that point, lazy loading failed.
>>> The code that loads the children is located in
>>> TwoPhaseLoad#initializeEntity(..) (called by
>>> QueryLoader#initializeEntitiesAndCollections):
>>> Object[] hydratedState = entityEntry.getLoadedState();
>>>
>>> if ( log.isDebugEnabled() )
>>> log.debug("resolving associations for " +
>>> MessageHelper.infoString(persister, id, session.getFactory()));
>>> Type[] types = persister.getPropertyTypes();
>>> for ( int i = 0; i < hydratedState.length; i++ ) {
>>> final Object value = hydratedState[i];
>>> if ( value!=LazyPropertyInitializer.UNFETCHED_PROPERTY &&
>>> value!=BackrefPropertyAccessor.UNKNOWN ) {
>>> hydratedState[i] = types[i].resolve( value, session, entity );
>>> }
>>> }
>>> ...
>>>
>>> The hydratedState array corresponds to my root library. This one
>>> contains 2 MarkerObject instances set to NOT_NULL_COLLECTION
>>> regarding the 'books' and the 'writers' collections.
>>> The call to types[i].resolve( value, session, entity ) when types[i]
>>> is such a MarkerObject resolves it as a PersistentList with its data.
>>>
>>> I would expect a new MarkerObject set to UNFECTCHED_COLLECTION or a
>>> not loaded PersistentList (i.e a lazy one).
>>>
>>> Here is a copy, of the generated hibernate mapping where data are
>>> collections are well tagged as lazy ones.
>>>
>>> Help would be appreciated.
>>> Stephane.
>>>
>>>
>>> Mapping content :
>>> <?xml version="1.0" encoding="UTF-8"?>
>>> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping
>>> DTD 3.0//EN"
>>> "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
>>>
>>> <hibernate-mapping auto-import="false">
>>> <class name="org.eclipse.example.library.impl.BookImpl"
>>> entity-name="Book" abstract="false" lazy="true" table="`book`"
>>> proxy="org.eclipse.example.library.Book">
>>> <meta attribute="eclassName">Book</meta>
>>> <meta
>>> attribute="epackage">http:///org/eclipse/example/library.ecore</meta>
>>> <id type="long" name="e_id" column="e_id"
> access=" org.eclipse.emf.teneo.hibernate.mapping.identifier.Identifie rPropertyHandler ">
>
>>>
>>> <meta attribute="syntheticId">true</meta>
>>> <generator class="native"/>
>>> </id>
>>> <version name="e_version" column="e_version"
> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHandler ">
>
>>>
>>> <meta attribute="syntheticVersion">true</meta>
>>> </version>
>>> <property name="title" lazy="false" insert="true"
>>> update="true" not-null="false" unique="false" type="java.lang.String">
>>> <column not-null="false" unique="false" name="`title`"/>
>>> </property>
>>> <property name="pages" lazy="false" insert="true"
>>> update="true" not-null="false" unique="false" type="int">
>>> <column not-null="false" unique="false" name="`pages`"/>
>>> </property>
>>> <property name="category" lazy="false" not-null="false"
>>> insert="true" update="true" unique="false">
>>> <column not-null="false" unique="false" name="`category`"/>
>>> <type
>>> name="org.eclipse.emf.teneo.hibernate.mapping.ENumUserType" >
>>> <param
>>> name="enumClass">org.eclipse.example.library.BookCategory</param >
>>> </type>
>>> </property>
>>> <many-to-one name="author" entity-name="Writer" lazy="proxy"
>>> foreign-key="book_author" insert="true" update="true" not-null="false">
>>> <column not-null="false" unique="false"
>>> name="`book_author_e_id`"/>
>>> </many-to-one>
>>> </class>
>>> <class name="org.eclipse.example.library.impl.LibraryImpl"
>>> entity-name="Library" abstract="false" lazy="true" table="`library`"
>>> proxy="org.eclipse.example.library.Library">
>>> <meta attribute="eclassName">Library</meta>
>>> <meta
>>> attribute="epackage">http:///org/eclipse/example/library.ecore</meta>
>>> <id type="long" name="e_id" column="e_id"
> access=" org.eclipse.emf.teneo.hibernate.mapping.identifier.Identifie rPropertyHandler ">
>
>>>
>>> <meta attribute="syntheticId">true</meta>
>>> <generator class="native"/>
>>> </id>
>>> <version name="e_version" column="e_version"
> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHandler ">
>
>>>
>>> <meta attribute="syntheticVersion">true</meta>
>>> </version>
>>> <property name="name" lazy="false" insert="true"
>>> update="true" not-null="false" unique="false" type="java.lang.String">
>>> <column not-null="false" unique="false" name="`name`"/>
>>> </property>
>>> <list name="writers" lazy="true" cascade="all,delete-orphan">
>>> <key update="true" foreign-key="library_writers">
>>> <column name="`library_writers_e_id`"
>>> not-null="false" unique="false"/>
>>> </key>
>>> <list-index column="`library_writers_idx`"/>
>>> <one-to-many entity-name="Writer"/>
>>> </list>
>>> <list name="books" lazy="true" cascade="all,delete-orphan">
>>> <key update="true" foreign-key="library_books">
>>> <column name="`library_books_e_id`" not-null="false"
>>> unique="false"/>
>>> </key>
>>> <list-index column="`library_books_idx`"/>
>>> <one-to-many entity-name="Book"/>
>>> </list>
>>> </class>
>>> <class name="org.eclipse.example.library.impl.WriterImpl"
>>> entity-name="Writer" abstract="false" lazy="true" table="`writer`"
>>> proxy="org.eclipse.example.library.Writer">
>>> <meta attribute="eclassName">Writer</meta>
>>> <meta
>>> attribute="epackage">http:///org/eclipse/example/library.ecore</meta>
>>> <id type="long" name="e_id" column="e_id"
> access=" org.eclipse.emf.teneo.hibernate.mapping.identifier.Identifie rPropertyHandler ">
>
>>>
>>> <meta attribute="syntheticId">true</meta>
>>> <generator class="native"/>
>>> </id>
>>> <version name="e_version" column="e_version"
> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHandler ">
>
>>>
>>> <meta attribute="syntheticVersion">true</meta>
>>> </version>
>>> <property name="name" lazy="false" insert="true"
>>> update="true" not-null="false" unique="false" type="java.lang.String">
>>> <column not-null="false" unique="false" name="`name`"/>
>>> </property>
>>> <list name="books" table="`writer_books`" lazy="true">
>>> <key update="true">
>>> <column name="`writer_e_id`" not-null="true"
>>> unique="false"/>
>>> </key>
>>> <list-index column="`writer_books_idx`"/>
>>> <many-to-many entity-name="Book" unique="true">
>>> <column name="`book_e_id`" not-null="true"
>>> unique="false"/>
>>> </many-to-many>
>>> </list>
>>> </class>
>>> </hibernate-mapping>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>
>
>
>


--

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] hibernate collection lazy loading behavior ? [message #425714 is a reply to message #425686] Fri, 05 December 2008 13:03 Go to previous messageGo to next message
Guillaume Brocard is currently offline Guillaume BrocardFriend
Messages: 25
Registered: July 2009
Junior Member
Hi Martin,

Stéphane has just sent you an e-mail with sample projects so as to
demonstrate the issue (if any).
We forgot to mention that the connection parameters are declared in the
activator of the library editor.

Just one last thing, this is using the very simple Library/Book/Writer
model, with no sub library and no feature map.

Thanks,
Guillaume.

PS :
My name is Guillaume. I must have stupidly switched my first name and my
last name at creation time.

Martin Taal wrote:

> Hi Brocard,
> Yes I can see what you mean but I would need to debug locally to see what
goes on. Can you email me
> a test Eclipse project with a database dump (mysql)? Hibernate libs are not
needed. Then I can try
> myself.

> gr. Martin

> Brocard Guillaume wrote:
>> Hi Martin,
>>
>> I'm working with Stéphane on this, and since he can't answer right now,
>> I'm taking up the torch.
>>
>> I have conducted the very same test with the extended library model (the
>> one with feature map), and basically, the objects stored in the database
>> are looking like the following tree :
>>
>> Library demo
>> Library NoName
>> Book book1
>> Writer writer2
>> Borrower borrower3
>> Library library4
>> Library library5
>> Book book6
>> ...
>> ...
>> Borrower borrower9999
>> Book book10000
>>
>> So objects are being possessed through libraries, using either the
>> Library.stock, Library.people, or Library.branches containment
>> relationships.
>>
>> We are using a HibernateResource, with initial query set to :
>> "SELECT library FROM Library library WHERE library.name='demo'"
>>
>> As I debug the loading of my resource (
>> HibernateResource.loadUsingDefinedQueries(SessionWrapper sess); line 500) :
>> final List<?> qryResult = sess.executeQuery(element);
>> the resulting list does contain Library Demo.
>>
>> Unfortunately, its branches list is initialized with Library NoName,
>> which in turn is initialized with book1, writer2, ..., library4, ...
>> book10000 all resolved.
>>
>> As Stéphane said, that has to do with the hydrated states of the objects
>> (see Stéphane's explanations).
>> What are we missing here ?
>>
>> Thanks in advance,
>> Guillaume.
>>
>>
>> Martin Taal wrote:
>>
>>> Hi Stéphane,
>>> I tested this and with me it worked fine.
>>
>>> This is for example the mapping for the library.books:
>>> <list name="books" lazy="true" cascade="all,delete-orphan">
>>> <key update="true" foreign-key="library_books">
>>> <column name="`library_books_e_id`" not-null="false"
>>> unique="false"/>
>>> </key>
>>> <list-index column="`library_books_idx`"/>
>>> <one-to-many entity-name="Book"/>
>>> </list>
>>
>>> and when I get the library it is not loaded:
>>> Library lib = (Library) res.getContents().get(0);
>>> only when I do this (in the testcase), the books get loaded:
>>> assertEquals(3, lib.getBooks().size());
>>
>>> Some info, an unloaded Hibernate persistentlist has a list member with
>>> value
>> null, if it is loaded
>>> there will be an arraylist in there.
>>
>>> With you the list member of the hibernate persistentlist is set?
>>
>>> gr. Martin
>>
>>
>>> Stéphane Fournier wrote:
>>>> Hi,
>>>> To continue from the previous post (see
>>
http://www.eclipse.org/newsportal/article.php?id=37502&g roup=eclipse.tools.emf#37502),
>>
>>>> I failed to load collections lazily. :(
>>>>
>>>> I tried with the very simple Library model with 3 classes :
>>>> Lib
>>> rary,
>>>> Book, Writer to avoid FeatureMap collections, Library that contains
>>>> other ones and so on...
>>>>
>>>> I create a root library with a book and its writer.
>>>>
>>>> Here the cfg parameters, I use to initialize the HbDataStore (sorry
>>>> for the code format due to copy/paste in the newsportal) :
>>>>
>>>> final Properties props = new Properties();
>>>> props.setProperty(Environment.DRIVER, "com.mysql.jdbc.Driver");
>>>> props.setProperty(Environment.USER, "lacarotte");
>>>> props.setProperty(Environment.URL,
>>>> "jdbc:mysql://localhost:3306/testOldLibrary");
>>>> props.setProperty(Environment.PASS, "lcelb");
>>>> props.setProperty(Environment.DIALECT,
>>>> org.hibernate.dialect.MySQLInnoDBDialect.class.getName());
>>>> props.setProperty(Environment.HBM2DDL_AUTO, "update");
>>>> props.setProperty(Environment.SHOW_SQL, Boolean.TRUE.toString());
>>>> props.setProperty(Environment.FORMAT_SQL, Boolean.TRUE.toString());
>>>> props.setProperty(Environment.DEFAULT_BATCH_FETCH_SIZE, "10");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING,
>>>> "JOINED");
>>>> props.setProperty(PersistenceOptions.DEFAULT_CACHE_STRATEGY,
>>>> "NONE");
>>>> props.setProperty(PersistenceOptions.SET_PROXY,
>>>> Boolean.TRUE.toString());
>>>>
>>>> // Initialize create the HbDataStore
>>>> HbDataStore hbds =
>>>> HbHelper.INSTANCE.createRegisterDataStore("library");
>>>>
>>>> hbds.setEPackages(new EPackage[] { LibraryPackage.eINSTANCE });
>>>> hbds.setProperties(props);
>>>> hbds.initialize();
>>>>
>>>> The resource is loaded with topClassesBehavior that runs a query
>>>> ("from library").
>>>> I debugged the query execution that returns the root library with its
>>>> children.
>>>> At that point, lazy loading failed.
>>>> The code that loads the children is located in
>>>> TwoPhaseLoad#initializeEntity(..) (called by
>>>> QueryLoader#initializeEntitiesAndCollections):
>>>> Object[] hydratedState = entityEntry.getLoadedState();
>>>>
>>>> if ( log.isDebugEnabled() )
>>>> log.debug("resolving associations for " +
>>>> MessageHelper.infoString(persister, id, session.getFactory()));
>>>> Type[] types = persister.getPropertyTypes();
>>>> for ( int i = 0; i < hydratedState.length; i++ ) {
>>>> final Object value = hydratedState[i];
>>>> if ( value!=LazyPropertyInitializer.UNFETCHED_PROPERTY &&
>>>> value!=BackrefPropertyAccessor.UNKNOWN ) {
>>>> hydratedState[i] = types[i].resolve( value, session, entity );
>>>> }
>>>> }
>>>> ...
>>>>
>>>> The hydratedState array corresponds to my root library. This one
>>>> contains 2 MarkerObject instances set to NOT_NULL_COLLECTION
>>>> regarding the 'books' and the 'writers' collections.
>>>> The call to types[i].resolve( value, session, entity ) when types[i]
>>>> is such a MarkerObject resolves it as a PersistentList with its data.
>>>>
>>>> I would expect a new MarkerObject set to UNFECTCHED_COLLECTION or a
>>>> not loaded PersistentList (i.e a lazy one).
>>>>
>>>> Here is a copy, of the generated hibernate mapping where data are
>>>> collections are well tagged as lazy ones.
>>>>
>>>> Help would be appreciated.
>>>> Stephane.
>>>>
>>>>
>>>> Mapping content :
>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping
>>>> DTD 3.0//EN"
>>>> "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
>>>>
>>>> <hibernate-mapping auto-import="false">
>>>> <class name="org.eclipse.example.library.impl.BookImpl"
>>>> entity-name="Book" abstract="false" lazy="true" table="`book`"
>>>> proxy="org.eclipse.example.library.Book">
>>>> <meta attribute="eclassName">Book</meta>
>>>> <meta
>>>> attribute="epackage">http:///org/eclipse/example/library.ecore</meta>
>>>> <id type="long" name="e_id" column="e_id"
>>
access=" org.eclipse.emf.teneo.hibernate.mapping.identifier.Identifie rPropertyHandler ">
>>
>>>>
>>>> <meta attribute="syntheticId">true</meta>
>>>> <generator class="native"/>
>>>> </id>
>>>> <version name="e_version" column="e_version"
>>
access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHandler ">
>>
>>>>
>>>> <meta attribute="syntheticVersion">true</meta>
>>>> </version>
>>>> <property name="title" lazy="false" insert="true"
>>>> update="true" not-null="false" unique="false" type="java.lang.String">
>>>> <column not-null="false" unique="false" name="`title`"/>
>>>> </property>
>>>> <property name="pages" lazy="false" insert="true"
>>>> update="true" not-null="false" unique="false" type="int">
>>>> <column not-null="false" unique="false" name="`pages`"/>
>>>> </property>
>>>> <property name="category" lazy="false" not-null="false"
>>>> insert="true" update="true" unique="false">
>>>> <column not-null="false" unique="false" name="`category`"/>
>>>> <type
>>>> name="org.eclipse.emf.teneo.hibernate.mapping.ENumUserType" >
>>>> <param
>>>> name="enumClass">org.eclipse.example.library.BookCategory</param >
>>>> </type>
>>>> </property>
>>>> <many-to-one name="author" entity-name="Writer" lazy="proxy"
>>>> foreign-key="book_author" insert="true" update="true" not-null="false">
>>>> <column not-null="false" unique="false"
>>>> name="`book_author_e_id`"/>
>>>> </many-to-one>
>>>> </class>
>>>> <class name="org.eclipse.example.library.impl.LibraryImpl"
>>>> entity-name="Library" abstract="false" lazy="true" table="`library`"
>>>> proxy="org.eclipse.example.library.Library">
>>>> <meta attribute="eclassName">Library</meta>
>>>> <meta
>>>> attribute="epackage">http:///org/eclipse/example/library.ecore</meta>
>>>> <id type="long" name="e_id" column="e_id"
>>
access=" org.eclipse.emf.teneo.hibernate.mapping.identifier.Identifie rPropertyHandler ">
>>
>>>>
>>>> <meta attribute="syntheticId">true</meta>
>>>> <generator class="native"/>
>>>> </id>
>>>> <version name="e_version" column="e_version"
>>
access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHandler ">
>>
>>>>
>>>> <meta attribute="syntheticVersion">true</meta>
>>>> </version>
>>>> <property name="name" lazy="false" insert="true"
>>>> update="true" not-null="false" unique="false" type="java.lang.String">
>>>> <column not-null="false" unique="false" name="`name`"/>
>>>> </property>
>>>> <list name="writers" lazy="true" cascade="all,delete-orphan">
>>>> <key update="true" foreign-key="library_writers">
>>>> <column name="`library_writers_e_id`"
>>>> not-null="false" unique="false"/>
>>>> </key>
>>>> <list-index column="`library_writers_idx`"/>
>>>> <one-to-many entity-name="Writer"/>
>>>> </list>
>>>> <list name="books" lazy="true" cascade="all,delete-orphan">
>>>> <key update="true" foreign-key="library_books">
>>>> <column name="`library_books_e_id`" not-null="false"
>>>> unique="false"/>
>>>> </key>
>>>> <list-index column="`library_books_idx`"/>
>>>> <one-to-many entity-name="Book"/>
>>>> </list>
>>>> </class>
>>>> <class name="org.eclipse.example.library.impl.WriterImpl"
>>>> entity-name="Writer" abstract="false" lazy="true" table="`writer`"
>>>> proxy="org.eclipse.example.library.Writer">
>>>> <meta attribute="eclassName">Writer</meta>
>>>> <meta
>>>> attribute="epackage">http:///org/eclipse/example/library.ecore</meta>
>>>> <id type="long" name="e_id" column="e_id"
>>
access=" org.eclipse.emf.teneo.hibernate.mapping.identifier.Identifie rPropertyHandler ">
>>
>>>>
>>>> <meta attribute="syntheticId">true</meta>
>>>> <generator class="native"/>
>>>> </id>
>>>> <version name="e_version" column="e_version"
>>
access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHandler ">
>>
>>>>
>>>> <meta attribute="syntheticVersion">true</meta>
>>>> </version>
>>>> <property name="name" lazy="false" insert="true"
>>>> update="true" not-null="false" unique="false" type="java.lang.String">
>>>> <column not-null="false" unique="false" name="`name`"/>
>>>> </property>
>>>> <list name="books" table="`writer_books`" lazy="true">
>>>> <key update="true">
>>>> <column name="`writer_e_id`" not-null="true"
>>>> unique="false"/>
>>>> </key>
>>>> <list-index column="`writer_books_idx`"/>
>>>> <many-to-many entity-name="Book" unique="true">
>>>> <column name="`book_e_id`" not-null="true"
>>>> unique="false"/>
>>>> </many-to-many>
>>>> </list>
>>>> </class>
>>>> </hibernate-mapping>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>
>>
>>
>>
Re: [Teneo] hibernate collection lazy loading behavior ? [message #425716 is a reply to message #425714] Fri, 05 December 2008 13:13 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Guillaume Brocard :-),
I received it, I will look at this weekend.

gr. Martin

Brocard Guillaume wrote:
> Hi Martin,
>
> Stéphane has just sent you an e-mail with sample projects so as to
> demonstrate the issue (if any).
> We forgot to mention that the connection parameters are declared in the
> activator of the library editor.
>
> Just one last thing, this is using the very simple Library/Book/Writer
> model, with no sub library and no feature map.
>
> Thanks,
> Guillaume.
>
> PS :
> My name is Guillaume. I must have stupidly switched my first name and my
> last name at creation time.
>
> Martin Taal wrote:
>
>> Hi Brocard,
>> Yes I can see what you mean but I would need to debug locally to see what
> goes on. Can you email me
>> a test Eclipse project with a database dump (mysql)? Hibernate libs
>> are not
> needed. Then I can try
>> myself.
>
>> gr. Martin
>
>> Brocard Guillaume wrote:
>>> Hi Martin,
>>>
>>> I'm working with Stéphane on this, and since he can't answer right
>>> now, I'm taking up the torch.
>>>
>>> I have conducted the very same test with the extended library model
>>> (the one with feature map), and basically, the objects stored in the
>>> database are looking like the following tree :
>>>
>>> Library demo
>>> Library NoName
>>> Book book1
>>> Writer writer2
>>> Borrower borrower3
>>> Library library4
>>> Library library5
>>> Book book6
>>> ...
>>> ...
>>> Borrower borrower9999
>>> Book book10000
>>>
>>> So objects are being possessed through libraries, using either the
>>> Library.stock, Library.people, or Library.branches containment
>>> relationships.
>>>
>>> We are using a HibernateResource, with initial query set to :
>>> "SELECT library FROM Library library WHERE library.name='demo'"
>>>
>>> As I debug the loading of my resource (
>>> HibernateResource.loadUsingDefinedQueries(SessionWrapper sess); line
>>> 500) :
>>> final List<?> qryResult = sess.executeQuery(element);
>>> the resulting list does contain Library Demo.
>>>
>>> Unfortunately, its branches list is initialized with Library NoName,
>>> which in turn is initialized with book1, writer2, ..., library4, ...
>>> book10000 all resolved.
>>>
>>> As Stéphane said, that has to do with the hydrated states of the
>>> objects (see Stéphane's explanations).
>>> What are we missing here ?
>>>
>>> Thanks in advance,
>>> Guillaume.
>>>
>>>
>>> Martin Taal wrote:
>>>
>>>> Hi Stéphane,
>>>> I tested this and with me it worked fine.
>>>
>>>> This is for example the mapping for the library.books:
>>>> <list name="books" lazy="true" cascade="all,delete-orphan">
>>>> <key update="true" foreign-key="library_books">
>>>> <column name="`library_books_e_id`" not-null="false"
>>>> unique="false"/>
>>>> </key>
>>>> <list-index column="`library_books_idx`"/>
>>>> <one-to-many entity-name="Book"/>
>>>> </list>
>>>
>>>> and when I get the library it is not loaded:
>>>> Library lib = (Library) res.getContents().get(0);
>>>> only when I do this (in the testcase), the books get loaded:
>>>> assertEquals(3, lib.getBooks().size());
>>>
>>>> Some info, an unloaded Hibernate persistentlist has a list member
>>>> with value
>>> null, if it is loaded
>>>> there will be an arraylist in there.
>>>
>>>> With you the list member of the hibernate persistentlist is set?
>>>
>>>> gr. Martin
>>>
>>>
>>>> Stéphane Fournier wrote:
>>>>> Hi,
>>>>> To continue from the previous post (see
>>>
> http://www.eclipse.org/newsportal/article.php?id=37502&g roup=eclipse.tools.emf#37502),
>
>>>
>>>>> I failed to load collections lazily. :(
>>>>>
>>>>> I tried with the very simple Library model with 3 classes :
>>>>> Lib
>>>> rary,
>>>>> Book, Writer to avoid FeatureMap collections, Library that contains
>>>>> other ones and so on...
>>>>>
>>>>> I create a root library with a book and its writer.
>>>>>
>>>>> Here the cfg parameters, I use to initialize the HbDataStore (sorry
>>>>> for the code format due to copy/paste in the newsportal) :
>>>>>
>>>>> final Properties props = new Properties();
>>>>> props.setProperty(Environment.DRIVER, "com.mysql.jdbc.Driver");
>>>>> props.setProperty(Environment.USER, "lacarotte");
>>>>> props.setProperty(Environment.URL,
>>>>> "jdbc:mysql://localhost:3306/testOldLibrary");
>>>>> props.setProperty(Environment.PASS, "lcelb");
>>>>> props.setProperty(Environment.DIALECT,
>>>>> org.hibernate.dialect.MySQLInnoDBDialect.class.getName());
>>>>> props.setProperty(Environment.HBM2DDL_AUTO, "update");
>>>>> props.setProperty(Environment.SHOW_SQL, Boolean.TRUE.toString());
>>>>> props.setProperty(Environment.FORMAT_SQL,
>>>>> Boolean.TRUE.toString());
>>>>> props.setProperty(Environment.DEFAULT_BATCH_FETCH_SIZE, "10");
>>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING,
>>>>> "JOINED");
>>>>> props.setProperty(PersistenceOptions.DEFAULT_CACHE_STRATEGY,
>>>>> "NONE");
>>>>> props.setProperty(PersistenceOptions.SET_PROXY,
>>>>> Boolean.TRUE.toString());
>>>>>
>>>>> // Initialize create the HbDataStore
>>>>> HbDataStore hbds =
>>>>> HbHelper.INSTANCE.createRegisterDataStore("library");
>>>>>
>>>>> hbds.setEPackages(new EPackage[] { LibraryPackage.eINSTANCE });
>>>>> hbds.setProperties(props);
>>>>> hbds.initialize();
>>>>>
>>>>> The resource is loaded with topClassesBehavior that runs a query
>>>>> ("from library").
>>>>> I debugged the query execution that returns the root library with
>>>>> its children.
>>>>> At that point, lazy loading failed.
>>>>> The code that loads the children is located in
>>>>> TwoPhaseLoad#initializeEntity(..) (called by
>>>>> QueryLoader#initializeEntitiesAndCollections):
>>>>> Object[] hydratedState = entityEntry.getLoadedState();
>>>>>
>>>>> if ( log.isDebugEnabled() )
>>>>> log.debug("resolving associations for " +
>>>>> MessageHelper.infoString(persister, id, session.getFactory()));
>>>>> Type[] types = persister.getPropertyTypes();
>>>>> for ( int i = 0; i < hydratedState.length; i++ ) {
>>>>> final Object value = hydratedState[i];
>>>>> if ( value!=LazyPropertyInitializer.UNFETCHED_PROPERTY &&
>>>>> value!=BackrefPropertyAccessor.UNKNOWN ) {
>>>>> hydratedState[i] = types[i].resolve( value, session, entity );
>>>>> }
>>>>> }
>>>>> ...
>>>>>
>>>>> The hydratedState array corresponds to my root library. This one
>>>>> contains 2 MarkerObject instances set to NOT_NULL_COLLECTION
>>>>> regarding the 'books' and the 'writers' collections.
>>>>> The call to types[i].resolve( value, session, entity ) when
>>>>> types[i] is such a MarkerObject resolves it as a PersistentList
>>>>> with its data.
>>>>>
>>>>> I would expect a new MarkerObject set to UNFECTCHED_COLLECTION or a
>>>>> not loaded PersistentList (i.e a lazy one).
>>>>>
>>>>> Here is a copy, of the generated hibernate mapping where data are
>>>>> collections are well tagged as lazy ones.
>>>>>
>>>>> Help would be appreciated.
>>>>> Stephane.
>>>>>
>>>>>
>>>>> Mapping content :
>>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping
>>>>> DTD 3.0//EN"
>>>>> "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
>>>>>
>>>>> <hibernate-mapping auto-import="false">
>>>>> <class name="org.eclipse.example.library.impl.BookImpl"
>>>>> entity-name="Book" abstract="false" lazy="true" table="`book`"
>>>>> proxy="org.eclipse.example.library.Book">
>>>>> <meta attribute="eclassName">Book</meta>
>>>>> <meta
>>>>> attribute="epackage">http:///org/eclipse/example/library.ecore</meta>
>>>>> <id type="long" name="e_id" column="e_id"
>>>
> access=" org.eclipse.emf.teneo.hibernate.mapping.identifier.Identifie rPropertyHandler ">
>
>>>
>>>>>
>>>>> <meta attribute="syntheticId">true</meta>
>>>>> <generator class="native"/>
>>>>> </id>
>>>>> <version name="e_version" column="e_version"
>>>
> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHandler ">
>
>>>
>>>>>
>>>>> <meta attribute="syntheticVersion">true</meta>
>>>>> </version>
>>>>> <property name="title" lazy="false" insert="true"
>>>>> update="true" not-null="false" unique="false" type="java.lang.String">
>>>>> <column not-null="false" unique="false" name="`title`"/>
>>>>> </property>
>>>>> <property name="pages" lazy="false" insert="true"
>>>>> update="true" not-null="false" unique="false" type="int">
>>>>> <column not-null="false" unique="false" name="`pages`"/>
>>>>> </property>
>>>>> <property name="category" lazy="false" not-null="false"
>>>>> insert="true" update="true" unique="false">
>>>>> <column not-null="false" unique="false"
>>>>> name="`category`"/>
>>>>> <type
>>>>> name="org.eclipse.emf.teneo.hibernate.mapping.ENumUserType" >
>>>>> <param
>>>>> name="enumClass">org.eclipse.example.library.BookCategory</param >
>>>>> </type>
>>>>> </property>
>>>>> <many-to-one name="author" entity-name="Writer"
>>>>> lazy="proxy" foreign-key="book_author" insert="true" update="true"
>>>>> not-null="false">
>>>>> <column not-null="false" unique="false"
>>>>> name="`book_author_e_id`"/>
>>>>> </many-to-one>
>>>>> </class>
>>>>> <class name="org.eclipse.example.library.impl.LibraryImpl"
>>>>> entity-name="Library" abstract="false" lazy="true"
>>>>> table="`library`" proxy="org.eclipse.example.library.Library">
>>>>> <meta attribute="eclassName">Library</meta>
>>>>> <meta
>>>>> attribute="epackage">http:///org/eclipse/example/library.ecore</meta>
>>>>> <id type="long" name="e_id" column="e_id"
>>>
> access=" org.eclipse.emf.teneo.hibernate.mapping.identifier.Identifie rPropertyHandler ">
>
>>>
>>>>>
>>>>> <meta attribute="syntheticId">true</meta>
>>>>> <generator class="native"/>
>>>>> </id>
>>>>> <version name="e_version" column="e_version"
>>>
> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHandler ">
>
>>>
>>>>>
>>>>> <meta attribute="syntheticVersion">true</meta>
>>>>> </version>
>>>>> <property name="name" lazy="false" insert="true"
>>>>> update="true" not-null="false" unique="false" type="java.lang.String">
>>>>> <column not-null="false" unique="false" name="`name`"/>
>>>>> </property>
>>>>> <list name="writers" lazy="true" cascade="all,delete-orphan">
>>>>> <key update="true" foreign-key="library_writers">
>>>>> <column name="`library_writers_e_id`"
>>>>> not-null="false" unique="false"/>
>>>>> </key>
>>>>> <list-index column="`library_writers_idx`"/>
>>>>> <one-to-many entity-name="Writer"/>
>>>>> </list>
>>>>> <list name="books" lazy="true" cascade="all,delete-orphan">
>>>>> <key update="true" foreign-key="library_books">
>>>>> <column name="`library_books_e_id`"
>>>>> not-null="false" unique="false"/>
>>>>> </key>
>>>>> <list-index column="`library_books_idx`"/>
>>>>> <one-to-many entity-name="Book"/>
>>>>> </list>
>>>>> </class>
>>>>> <class name="org.eclipse.example.library.impl.WriterImpl"
>>>>> entity-name="Writer" abstract="false" lazy="true" table="`writer`"
>>>>> proxy="org.eclipse.example.library.Writer">
>>>>> <meta attribute="eclassName">Writer</meta>
>>>>> <meta
>>>>> attribute="epackage">http:///org/eclipse/example/library.ecore</meta>
>>>>> <id type="long" name="e_id" column="e_id"
>>>
> access=" org.eclipse.emf.teneo.hibernate.mapping.identifier.Identifie rPropertyHandler ">
>
>>>
>>>>>
>>>>> <meta attribute="syntheticId">true</meta>
>>>>> <generator class="native"/>
>>>>> </id>
>>>>> <version name="e_version" column="e_version"
>>>
> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHandler ">
>
>>>
>>>>>
>>>>> <meta attribute="syntheticVersion">true</meta>
>>>>> </version>
>>>>> <property name="name" lazy="false" insert="true"
>>>>> update="true" not-null="false" unique="false" type="java.lang.String">
>>>>> <column not-null="false" unique="false" name="`name`"/>
>>>>> </property>
>>>>> <list name="books" table="`writer_books`" lazy="true">
>>>>> <key update="true">
>>>>> <column name="`writer_e_id`" not-null="true"
>>>>> unique="false"/>
>>>>> </key>
>>>>> <list-index column="`writer_books_idx`"/>
>>>>> <many-to-many entity-name="Book" unique="true">
>>>>> <column name="`book_e_id`" not-null="true"
>>>>> unique="false"/>
>>>>> </many-to-many>
>>>>> </list>
>>>>> </class>
>>>>> </hibernate-mapping>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>
>>>
>>>
>>>
>
>
>
>


--

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] hibernate collection lazy loading behavior ? [message #425748 is a reply to message #425716] Fri, 05 December 2008 23:13 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Stephane, Guillaume,
Your test project worked fine. I put a breakpoint in the HibernateResource. Then I opened the
editor, after stepping through the code I ended up in the method loadResource (in HibernateResource)
there the content of the resource is loaded in the storeList. When I look in the storeList there is
one library with two collections books and writers, both HibernatePersistableEList.

Now comes the tricky part: In the variables view I look at the content:
- if I click with my mouse on the books or writers (the label) then hibernate loads the list (as is
visible in the console). The same when I click on the label delegate within books/writers. I assume
that the debugger forces the list to load by asking for its contents or something.
- when I however click on the little triangle before the label the debug view opens the
HibernatePersistableList without loading the list. The same for the little triangle before the delegate.
- if you do this (open through the triangle) then you will see that the
hibernatepersistablelist.delegate has a list member which is null. So this means that after the load
of the library from the database, the writers and books list have not yet been loaded.

Let me know if you see other behavior.

gr. Martin

Martin Taal wrote:
> Hi Guillaume Brocard :-),
> I received it, I will look at this weekend.
>
> gr. Martin
>
> Brocard Guillaume wrote:
>> Hi Martin,
>>
>> Stéphane has just sent you an e-mail with sample projects so as to
>> demonstrate the issue (if any).
>> We forgot to mention that the connection parameters are declared in
>> the activator of the library editor.
>>
>> Just one last thing, this is using the very simple Library/Book/Writer
>> model, with no sub library and no feature map.
>>
>> Thanks,
>> Guillaume.
>>
>> PS :
>> My name is Guillaume. I must have stupidly switched my first name and
>> my last name at creation time.
>>
>> Martin Taal wrote:
>>
>>> Hi Brocard,
>>> Yes I can see what you mean but I would need to debug locally to see
>>> what
>> goes on. Can you email me
>>> a test Eclipse project with a database dump (mysql)? Hibernate libs
>>> are not
>> needed. Then I can try
>>> myself.
>>
>>> gr. Martin
>>
>>> Brocard Guillaume wrote:
>>>> Hi Martin,
>>>>
>>>> I'm working with Stéphane on this, and since he can't answer right
>>>> now, I'm taking up the torch.
>>>>
>>>> I have conducted the very same test with the extended library model
>>>> (the one with feature map), and basically, the objects stored in the
>>>> database are looking like the following tree :
>>>>
>>>> Library demo
>>>> Library NoName
>>>> Book book1
>>>> Writer writer2
>>>> Borrower borrower3
>>>> Library library4
>>>> Library library5
>>>> Book book6
>>>> ...
>>>> ...
>>>> Borrower borrower9999
>>>> Book book10000
>>>>
>>>> So objects are being possessed through libraries, using either the
>>>> Library.stock, Library.people, or Library.branches containment
>>>> relationships.
>>>>
>>>> We are using a HibernateResource, with initial query set to :
>>>> "SELECT library FROM Library library WHERE library.name='demo'"
>>>>
>>>> As I debug the loading of my resource (
>>>> HibernateResource.loadUsingDefinedQueries(SessionWrapper sess); line
>>>> 500) :
>>>> final List<?> qryResult = sess.executeQuery(element);
>>>> the resulting list does contain Library Demo.
>>>>
>>>> Unfortunately, its branches list is initialized with Library NoName,
>>>> which in turn is initialized with book1, writer2, ..., library4, ...
>>>> book10000 all resolved.
>>>>
>>>> As Stéphane said, that has to do with the hydrated states of the
>>>> objects (see Stéphane's explanations).
>>>> What are we missing here ?
>>>>
>>>> Thanks in advance,
>>>> Guillaume.
>>>>
>>>>
>>>> Martin Taal wrote:
>>>>
>>>>> Hi Stéphane,
>>>>> I tested this and with me it worked fine.
>>>>
>>>>> This is for example the mapping for the library.books:
>>>>> <list name="books" lazy="true" cascade="all,delete-orphan">
>>>>> <key update="true" foreign-key="library_books">
>>>>> <column name="`library_books_e_id`"
>>>>> not-null="false" unique="false"/>
>>>>> </key>
>>>>> <list-index column="`library_books_idx`"/>
>>>>> <one-to-many entity-name="Book"/>
>>>>> </list>
>>>>
>>>>> and when I get the library it is not loaded:
>>>>> Library lib = (Library) res.getContents().get(0);
>>>>> only when I do this (in the testcase), the books get loaded:
>>>>> assertEquals(3, lib.getBooks().size());
>>>>
>>>>> Some info, an unloaded Hibernate persistentlist has a list member
>>>>> with value
>>>> null, if it is loaded
>>>>> there will be an arraylist in there.
>>>>
>>>>> With you the list member of the hibernate persistentlist is set?
>>>>
>>>>> gr. Martin
>>>>
>>>>
>>>>> Stéphane Fournier wrote:
>>>>>> Hi,
>>>>>> To continue from the previous post (see
>>>>
>> http://www.eclipse.org/newsportal/article.php?id=37502&g roup=eclipse.tools.emf#37502),
>>
>>>>
>>>>>> I failed to load collections lazily. :(
>>>>>>
>>>>>> I tried with the very simple Library model with 3 classes :
>>>>>> Lib
>>>>> rary,
>>>>>> Book, Writer to avoid FeatureMap collections, Library that
>>>>>> contains other ones and so on...
>>>>>>
>>>>>> I create a root library with a book and its writer.
>>>>>>
>>>>>> Here the cfg parameters, I use to initialize the HbDataStore
>>>>>> (sorry for the code format due to copy/paste in the newsportal) :
>>>>>>
>>>>>> final Properties props = new Properties();
>>>>>> props.setProperty(Environment.DRIVER, "com.mysql.jdbc.Driver");
>>>>>> props.setProperty(Environment.USER, "lacarotte");
>>>>>> props.setProperty(Environment.URL,
>>>>>> "jdbc:mysql://localhost:3306/testOldLibrary");
>>>>>> props.setProperty(Environment.PASS, "lcelb");
>>>>>> props.setProperty(Environment.DIALECT,
>>>>>> org.hibernate.dialect.MySQLInnoDBDialect.class.getName());
>>>>>> props.setProperty(Environment.HBM2DDL_AUTO, "update");
>>>>>> props.setProperty(Environment.SHOW_SQL,
>>>>>> Boolean.TRUE.toString());
>>>>>> props.setProperty(Environment.FORMAT_SQL,
>>>>>> Boolean.TRUE.toString());
>>>>>> props.setProperty(Environment.DEFAULT_BATCH_FETCH_SIZE, "10");
>>>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING,
>>>>>> "JOINED");
>>>>>> props.setProperty(PersistenceOptions.DEFAULT_CACHE_STRATEGY,
>>>>>> "NONE");
>>>>>> props.setProperty(PersistenceOptions.SET_PROXY,
>>>>>> Boolean.TRUE.toString());
>>>>>>
>>>>>> // Initialize create the HbDataStore
>>>>>> HbDataStore hbds =
>>>>>> HbHelper.INSTANCE.createRegisterDataStore("library");
>>>>>>
>>>>>> hbds.setEPackages(new EPackage[] { LibraryPackage.eINSTANCE });
>>>>>> hbds.setProperties(props);
>>>>>> hbds.initialize();
>>>>>>
>>>>>> The resource is loaded with topClassesBehavior that runs a query
>>>>>> ("from library").
>>>>>> I debugged the query execution that returns the root library with
>>>>>> its children.
>>>>>> At that point, lazy loading failed.
>>>>>> The code that loads the children is located in
>>>>>> TwoPhaseLoad#initializeEntity(..) (called by
>>>>>> QueryLoader#initializeEntitiesAndCollections):
>>>>>> Object[] hydratedState = entityEntry.getLoadedState();
>>>>>>
>>>>>> if ( log.isDebugEnabled() )
>>>>>> log.debug("resolving associations for " +
>>>>>> MessageHelper.infoString(persister, id, session.getFactory()));
>>>>>> Type[] types = persister.getPropertyTypes();
>>>>>> for ( int i = 0; i < hydratedState.length; i++ ) {
>>>>>> final Object value = hydratedState[i];
>>>>>> if ( value!=LazyPropertyInitializer.UNFETCHED_PROPERTY &&
>>>>>> value!=BackrefPropertyAccessor.UNKNOWN ) {
>>>>>> hydratedState[i] = types[i].resolve( value, session, entity );
>>>>>> }
>>>>>> }
>>>>>> ...
>>>>>>
>>>>>> The hydratedState array corresponds to my root library. This one
>>>>>> contains 2 MarkerObject instances set to NOT_NULL_COLLECTION
>>>>>> regarding the 'books' and the 'writers' collections.
>>>>>> The call to types[i].resolve( value, session, entity ) when
>>>>>> types[i] is such a MarkerObject resolves it as a PersistentList
>>>>>> with its data.
>>>>>>
>>>>>> I would expect a new MarkerObject set to UNFECTCHED_COLLECTION or
>>>>>> a not loaded PersistentList (i.e a lazy one).
>>>>>>
>>>>>> Here is a copy, of the generated hibernate mapping where data are
>>>>>> collections are well tagged as lazy ones.
>>>>>>
>>>>>> Help would be appreciated.
>>>>>> Stephane.
>>>>>>
>>>>>>
>>>>>> Mapping content :
>>>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>>> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping
>>>>>> DTD 3.0//EN"
>>>>>> "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
>>>>>>
>>>>>> <hibernate-mapping auto-import="false">
>>>>>> <class name="org.eclipse.example.library.impl.BookImpl"
>>>>>> entity-name="Book" abstract="false" lazy="true" table="`book`"
>>>>>> proxy="org.eclipse.example.library.Book">
>>>>>> <meta attribute="eclassName">Book</meta>
>>>>>> <meta
>>>>>> attribute="epackage">http:///org/eclipse/example/library.ecore</meta>
>>>>>> <id type="long" name="e_id" column="e_id"
>>>>
>> access=" org.eclipse.emf.teneo.hibernate.mapping.identifier.Identifie rPropertyHandler ">
>>
>>>>
>>>>>>
>>>>>> <meta attribute="syntheticId">true</meta>
>>>>>> <generator class="native"/>
>>>>>> </id>
>>>>>> <version name="e_version" column="e_version"
>>>>
>> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHandler ">
>>
>>>>
>>>>>>
>>>>>> <meta attribute="syntheticVersion">true</meta>
>>>>>> </version>
>>>>>> <property name="title" lazy="false" insert="true"
>>>>>> update="true" not-null="false" unique="false"
>>>>>> type="java.lang.String">
>>>>>> <column not-null="false" unique="false" name="`title`"/>
>>>>>> </property>
>>>>>> <property name="pages" lazy="false" insert="true"
>>>>>> update="true" not-null="false" unique="false" type="int">
>>>>>> <column not-null="false" unique="false" name="`pages`"/>
>>>>>> </property>
>>>>>> <property name="category" lazy="false" not-null="false"
>>>>>> insert="true" update="true" unique="false">
>>>>>> <column not-null="false" unique="false"
>>>>>> name="`category`"/>
>>>>>> <type
>>>>>> name="org.eclipse.emf.teneo.hibernate.mapping.ENumUserType" >
>>>>>> <param
>>>>>> name="enumClass">org.eclipse.example.library.BookCategory</param >
>>>>>> </type>
>>>>>> </property>
>>>>>> <many-to-one name="author" entity-name="Writer"
>>>>>> lazy="proxy" foreign-key="book_author" insert="true" update="true"
>>>>>> not-null="false">
>>>>>> <column not-null="false" unique="false"
>>>>>> name="`book_author_e_id`"/>
>>>>>> </many-to-one>
>>>>>> </class>
>>>>>> <class name="org.eclipse.example.library.impl.LibraryImpl"
>>>>>> entity-name="Library" abstract="false" lazy="true"
>>>>>> table="`library`" proxy="org.eclipse.example.library.Library">
>>>>>> <meta attribute="eclassName">Library</meta>
>>>>>> <meta
>>>>>> attribute="epackage">http:///org/eclipse/example/library.ecore</meta>
>>>>>> <id type="long" name="e_id" column="e_id"
>>>>
>> access=" org.eclipse.emf.teneo.hibernate.mapping.identifier.Identifie rPropertyHandler ">
>>
>>>>
>>>>>>
>>>>>> <meta attribute="syntheticId">true</meta>
>>>>>> <generator class="native"/>
>>>>>> </id>
>>>>>> <version name="e_version" column="e_version"
>>>>
>> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHandler ">
>>
>>>>
>>>>>>
>>>>>> <meta attribute="syntheticVersion">true</meta>
>>>>>> </version>
>>>>>> <property name="name" lazy="false" insert="true"
>>>>>> update="true" not-null="false" unique="false"
>>>>>> type="java.lang.String">
>>>>>> <column not-null="false" unique="false" name="`name`"/>
>>>>>> </property>
>>>>>> <list name="writers" lazy="true" cascade="all,delete-orphan">
>>>>>> <key update="true" foreign-key="library_writers">
>>>>>> <column name="`library_writers_e_id`"
>>>>>> not-null="false" unique="false"/>
>>>>>> </key>
>>>>>> <list-index column="`library_writers_idx`"/>
>>>>>> <one-to-many entity-name="Writer"/>
>>>>>> </list>
>>>>>> <list name="books" lazy="true" cascade="all,delete-orphan">
>>>>>> <key update="true" foreign-key="library_books">
>>>>>> <column name="`library_books_e_id`"
>>>>>> not-null="false" unique="false"/>
>>>>>> </key>
>>>>>> <list-index column="`library_books_idx`"/>
>>>>>> <one-to-many entity-name="Book"/>
>>>>>> </list>
>>>>>> </class>
>>>>>> <class name="org.eclipse.example.library.impl.WriterImpl"
>>>>>> entity-name="Writer" abstract="false" lazy="true" table="`writer`"
>>>>>> proxy="org.eclipse.example.library.Writer">
>>>>>> <meta attribute="eclassName">Writer</meta>
>>>>>> <meta
>>>>>> attribute="epackage">http:///org/eclipse/example/library.ecore</meta>
>>>>>> <id type="long" name="e_id" column="e_id"
>>>>
>> access=" org.eclipse.emf.teneo.hibernate.mapping.identifier.Identifie rPropertyHandler ">
>>
>>>>
>>>>>>
>>>>>> <meta attribute="syntheticId">true</meta>
>>>>>> <generator class="native"/>
>>>>>> </id>
>>>>>> <version name="e_version" column="e_version"
>>>>
>> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHandler ">
>>
>>>>
>>>>>>
>>>>>> <meta attribute="syntheticVersion">true</meta>
>>>>>> </version>
>>>>>> <property name="name" lazy="false" insert="true"
>>>>>> update="true" not-null="false" unique="false"
>>>>>> type="java.lang.String">
>>>>>> <column not-null="false" unique="false" name="`name`"/>
>>>>>> </property>
>>>>>> <list name="books" table="`writer_books`" lazy="true">
>>>>>> <key update="true">
>>>>>> <column name="`writer_e_id`" not-null="true"
>>>>>> unique="false"/>
>>>>>> </key>
>>>>>> <list-index column="`writer_books_idx`"/>
>>>>>> <many-to-many entity-name="Book" unique="true">
>>>>>> <column name="`book_e_id`" not-null="true"
>>>>>> unique="false"/>
>>>>>> </many-to-many>
>>>>>> </list>
>>>>>> </class>
>>>>>> </hibernate-mapping>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>
>>>>
>>>>
>>>>
>>
>>
>>
>>
>
>


--

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] hibernate collection lazy loading behavior ? [message #425765 is a reply to message #425748] Mon, 08 December 2008 13:23 Go to previous messageGo to next message
Guillaume Brocard is currently offline Guillaume BrocardFriend
Messages: 25
Registered: July 2009
Junior Member
Hi Martin,

I do not understand the 'little triangle' trick. Whenever I click it (for
collections, I can see a little (rotated yellow) square, no little
triangle), it is being resolved, as it selects the whole line.

Anyway, your analysis seems to be perfectly correct.
When displaying the sql queries, I can see that indeed, the initial query
is just asking for a library. And browsing through the editor nodes does
lead to new queries, as books and writers should be displayed.
I've been fooled by the debugging process...

However that still does not work with the extended library example, which
I am using along with the EMF Transaction framework (my application
requires that feature). It seems that the transaction change recorder is
loading the whole resource while adding itself as an adapter (at resource
loading time).

So Teneo is behaving exactly as expected, thanks a lot for your help (and
time).

Guillaume.

Martin Taal wrote:

> Hi Stephane, Guillaume,
> Your test project worked fine. I put a breakpoint in the HibernateResource.
Then I opened the
> editor, after stepping through the code I ended up in the method
loadResource (in HibernateResource)
> there the content of the resource is loaded in the storeList. When I look in
the storeList there is
> one library with two collections books and writers, both
HibernatePersistableEList.

> Now comes the tricky part: In the variables view I look at the content:
> - if I click with my mouse on the books or writers (the label) then
hibernate loads the list (as is
> visible in the console). The same when I click on the label delegate within
books/writers. I assume
> that the debugger forces the list to load by asking for its contents or
something.
> - when I however click on the little triangle before the label the debug
view opens the
> HibernatePersistableList without loading the list. The same for the little
triangle before the delegate.
> - if you do this (open through the triangle) then you will see that the
> hibernatepersistablelist.delegate has a list member which is null. So this
means that after the load
> of the library from the database, the writers and books list have not yet
been loaded.

> Let me know if you see other behavior.

> gr. Martin

> Martin Taal wrote:
>> Hi Guillaume Brocard :-),
>> I received it, I will look at this weekend.
>>
>> gr. Martin
>>
>> Brocard Guillaume wrote:
>>> Hi Martin,
>>>
>>> Stéphane has just sent you an e-mail with sample projects so as to
>>> demonstrate the issue (if any).
>>> We forgot to mention that the connection parameters are declared in
>>> the activator of the library editor.
>>>
>>> Just one last thing, this is using the very simple Library/Book/Writer
>>> model, with no sub library and no feature map.
>>>
>>> Thanks,
>>> Guillaume.
>>>
>>> PS :
>>> My name is Guillaume. I must have stupidly switched my first name and
>>> my last name at creation time.
>>>
>>> Martin Taal wrote:
>>>
>>>> Hi Brocard,
>>>> Yes I can see what you mean but I would need to debug locally to see
>>>> what
>>> goes on. Can you email me
>>>> a test Eclipse project with a database dump (mysql)? Hibernate libs
>>>> are not
>>> needed. Then I can try
>>>> myself.
>>>
>>>> gr. Martin
>>>
>>>> Brocard Guillaume wrote:
>>>>> Hi Martin,
>>>>>
>>>>> I'm working with Stéphane on this, and since he can't answer right
>>>>> now, I'm taking up the torch.
>>>>>
>>>>> I have conducted the very same test with the extended library model
>>>>> (the one with feature map), and basically, the objects stored in the
>>>>> database are looking like the following tree :
>>>>>
>>>>> Library demo
>>>>> Library NoName
>>>>> Book book1
>>>>> Writer writer2
>>>>> Borrower borrower3
>>>>> Library library4
>>>>> Library library5
>>>>> Book book6
>>>>> ...
>>>>> ...
>>>>> Borrower borrower9999
>>>>> Book book10000
>>>>>
>>>>> So objects are being possessed through libraries, using either the
>>>>> Library.stock, Library.people, or Library.branches containment
>>>>> relationships.
>>>>>
>>>>> We are using a HibernateResource, with initial query set to :
>>>>> "SELECT library FROM Library library WHERE library.name='demo'"
>>>>>
>>>>> As I debug the loading of my resource (
>>>>> HibernateResource.loadUsingDefinedQueries(SessionWrapper sess); line
>>>>> 500) :
>>>>> final List<?> qryResult = sess.executeQuery(element);
>>>>> the resulting list does contain Library Demo.
>>>>>
>>>>> Unfortunately, its branches list is initialized with Library NoName,
>>>>> which in turn is initialized with book1, writer2, ..., library4, ...
>>>>> book10000 all resolved.
>>>>>
>>>>> As Stéphane said, that has to do with the hydrated states of the
>>>>> objects (see Stéphane's explanations).
>>>>> What are we missing here ?
>>>>>
>>>>> Thanks in advance,
>>>>> Guillaume.
>>>>>
>>>>>
>>>>> Martin Taal wrote:
>>>>>
>>>>>> Hi Stéphane,
>>>>>> I tested this and with me it worked fine.
>>>>>
>>>>>> This is for example the mapping for the library.books:
>>>>>> <list name="books" lazy="true" cascade="all,delete-orphan">
>>>>>> <key update="true" foreign-key="library_books">
>>>>>> <column name="`library_books_e_id`"
>>>>>> not-null="false" unique="false"/>
>>>>>> </key>
>>>>>> <list-index column="`library_books_idx`"/>
>>>>>> <one-to-many entity-name="Book"/>
>>>>>> </list>
>>>>>
>>>>>> and when I get the library it is not loaded:
>>>>>> Library lib = (Library) res.getContents().get(0);
>>>>>> only when I do this (in the testcase), the books get loaded:
>>>>>> assertEquals(3, lib.getBooks().size());
>>>>>
>>>>>> Some info, an unloaded Hibernate persistentlist has a list member
>>>>>> with value
>>>>> null, if it is loaded
>>>>>> there will be an arraylist in there.
>>>>>
>>>>>> With you the list member of the hibernate persistentlist is set?
>>>>>
>>>>>> gr. Martin
>>>>>
>>>>>
>>>>>> Stéphane Fournier wrote:
>>>>>>> Hi,
>>>>>>> To continue from the previous post (see
>>>>>
>>>
http://www.eclipse.org/newsportal/article.php?id=37502&g roup=eclipse.tools.emf#37502),
>>>
>>>>>
>>>>>>> I failed to load collections lazily. :(
>>>>>>>
>>>>>>> I tried with the very simple Library model with 3 classes :
>>>>>>> Lib
>>>>>> rary,
>>>>>>> Book, Writer to avoid FeatureMap collections, Library that
>>>>>>> contains other ones and so on...
>>>>>>>
>>>>>>> I create a root library with a book and its writer.
>>>>>>>
>>>>>>> Here the cfg parameters, I use to initialize the HbDataStore
>>>>>>> (sorry for the code format due to copy/paste in the newsportal) :
>>>>>>>
>>>>>>> final Properties props = new Properties();
>>>>>>> props.setProperty(Environment.DRIVER, "com.mysql.jdbc.Driver");
>>>>>>> props.setProperty(Environment.USER, "lacarotte");
>>>>>>> props.setProperty(Environment.URL,
>>>>>>> "jdbc:mysql://localhost:3306/testOldLibrary");
>>>>>>> props.setProperty(Environment.PASS, "lcelb");
>>>>>>> props.setProperty(Environment.DIALECT,
>>>>>>> org.hibernate.dialect.MySQLInnoDBDialect.class.getName());
>>>>>>> props.setProperty(Environment.HBM2DDL_AUTO, "update");
>>>>>>> props.setProperty(Environment.SHOW_SQL,
>>>>>>> Boolean.TRUE.toString());
>>>>>>> props.setProperty(Environment.FORMAT_SQL,
>>>>>>> Boolean.TRUE.toString());
>>>>>>> props.setProperty(Environment.DEFAULT_BATCH_FETCH_SIZE, "10");
>>>>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING,
>>>>>>> "JOINED");
>>>>>>> props.setProperty(PersistenceOptions.DEFAULT_CACHE_STRATEGY,
>>>>>>> "NONE");
>>>>>>> props.setProperty(PersistenceOptions.SET_PROXY,
>>>>>>> Boolean.TRUE.toString());
>>>>>>>
>>>>>>> // Initialize create the HbDataStore
>>>>>>> HbDataStore hbds =
>>>>>>> HbHelper.INSTANCE.createRegisterDataStore("library");
>>>>>>>
>>>>>>> hbds.setEPackages(new EPackage[] { LibraryPackage.eINSTANCE });
>>>>>>> hbds.setProperties(props);
>>>>>>> hbds.initialize();
>>>>>>>
>>>>>>> The resource is loaded with topClassesBehavior that runs a query
>>>>>>> ("from library").
>>>>>>> I debugged the query execution that returns the root library with
>>>>>>> its children.
>>>>>>> At that point, lazy loading failed.
>>>>>>> The code that loads the children is located in
>>>>>>> TwoPhaseLoad#initializeEntity(..) (called by
>>>>>>> QueryLoader#initializeEntitiesAndCollections):
>>>>>>> Object[] hydratedState = entityEntry.getLoadedState();
>>>>>>>
>>>>>>> if ( log.isDebugEnabled() )
>>>>>>> log.debug("resolving associations for " +
>>>>>>> MessageHelper.infoString(persister, id, session.getFactory()));
>>>>>>> Type[] types = persister.getPropertyTypes();
>>>>>>> for ( int i = 0; i < hydratedState.length; i++ ) {
>>>>>>> final Object value = hydratedState[i];
>>>>>>> if ( value!=LazyPropertyInitializer.UNFETCHED_PROPERTY &&
>>>>>>> value!=BackrefPropertyAccessor.UNKNOWN ) {
>>>>>>> hydratedState[i] = types[i].resolve( value, session, entity );
>>>>>>> }
>>>>>>> }
>>>>>>> ...
>>>>>>>
>>>>>>> The hydratedState array corresponds to my root library. This one
>>>>>>> contains 2 MarkerObject instances set to NOT_NULL_COLLECTION
>>>>>>> regarding the 'books' and the 'writers' collections.
>>>>>>> The call to types[i].resolve( value, session, entity ) when
>>>>>>> types[i] is such a MarkerObject resolves it as a PersistentList
>>>>>>> with its data.
>>>>>>>
>>>>>>> I would expect a new MarkerObject set to UNFECTCHED_COLLECTION or
>>>>>>> a not loaded PersistentList (i.e a lazy one).
>>>>>>>
>>>>>>> Here is a copy, of the generated hibernate mapping where data are
>>>>>>> collections are well tagged as lazy ones.
>>>>>>>
>>>>>>> Help would be appreciated.
>>>>>>> Stephane.
>>>>>>>
>>>>>>>
>>>>>>> Mapping content :
>>>>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>>>> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping
>>>>>>> DTD 3.0//EN"
>>>>>>> "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
>>>>>>>
>>>>>>> <hibernate-mapping auto-import="false">
>>>>>>> <class name="org.eclipse.example.library.impl.BookImpl"
>>>>>>> entity-name="Book" abstract="false" lazy="true" table="`book`"
>>>>>>> proxy="org.eclipse.example.library.Book">
>>>>>>> <meta attribute="eclassName">Book</meta>
>>>>>>> <meta
>>>>>>> attribute="epackage">http:///org/eclipse/example/library.ecore</meta>
>>>>>>> <id type="long" name="e_id" column="e_id"
>>>>>
>>>
access=" org.eclipse.emf.teneo.hibernate.mapping.identifier.Identifie rPropertyHandler ">
>>>
>>>>>
>>>>>>>
>>>>>>> <meta attribute="syntheticId">true</meta>
>>>>>>> <generator class="native"/>
>>>>>>> </id>
>>>>>>> <version name="e_version" column="e_version"
>>>>>
>>>
access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHandler ">
>>>
>>>>>
>>>>>>>
>>>>>>> <meta attribute="syntheticVersion">true</meta>
>>>>>>> </version>
>>>>>>> <property name="title" lazy="false" insert="true"
>>>>>>> update="true" not-null="false" unique="false"
>>>>>>> type="java.lang.String">
>>>>>>> <column not-null="false" unique="false" name="`title`"/>
>>>>>>> </property>
>>>>>>> <property name="pages" lazy="false" insert="true"
>>>>>>> update="true" not-null="false" unique="false" type="int">
>>>>>>> <column not-null="false" unique="false" name="`pages`"/>
>>>>>>> </property>
>>>>>>> <property name="category" lazy="false" not-null="false"
>>>>>>> insert="true" update="true" unique="false">
>>>>>>> <column not-null="false" unique="false"
>>>>>>> name="`category`"/>
>>>>>>> <type
>>>>>>> name="org.eclipse.emf.teneo.hibernate.mapping.ENumUserType" >
>>>>>>> <param
>>>>>>> name="enumClass">org.eclipse.example.library.BookCategory</param >
>>>>>>> </type>
>>>>>>> </property>
>>>>>>> <many-to-one name="author" entity-name="Writer"
>>>>>>> lazy="proxy" foreign-key="book_author" insert="true" update="true"
>>>>>>> not-null="false">
>>>>>>> <column not-null="false" unique="false"
>>>>>>> name="`book_author_e_id`"/>
>>>>>>> </many-to-one>
>>>>>>> </class>
>>>>>>> <class name="org.eclipse.example.library.impl.LibraryImpl"
>>>>>>> entity-name="Library" abstract="false" lazy="true"
>>>>>>> table="`library`" proxy="org.eclipse.example.library.Library">
>>>>>>> <meta attribute="eclassName">Library</meta>
>>>>>>> <meta
>>>>>>> attribute="epackage">http:///org/eclipse/example/library.ecore</meta>
>>>>>>> <id type="long" name="e_id" column="e_id"
>>>>>
>>>
access=" org.eclipse.emf.teneo.hibernate.mapping.identifier.Identifie rPropertyHandler ">
>>>
>>>>>
>>>>>>>
>>>>>>> <meta attribute="syntheticId">true</meta>
>>>>>>> <generator class="native"/>
>>>>>>> </id>
>>>>>>> <version name="e_version" column="e_version"
>>>>>
>>>
access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHandler ">
>>>
>>>>>
>>>>>>>
>>>>>>> <meta attribute="syntheticVersion">true</meta>
>>>>>>> </version>
>>>>>>> <property name="name" lazy="false" insert="true"
>>>>>>> update="true" not-null="false" unique="false"
>>>>>>> type="java.lang.String">
>>>>>>> <column not-null="false" unique="false" name="`name`"/>
>>>>>>> </property>
>>>>>>> <list name="writers" lazy="true" cascade="all,delete-orphan">
>>>>>>> <key update="true" foreign-key="library_writers">
>>>>>>> <column name="`library_writers_e_id`"
>>>>>>> not-null="false" unique="false"/>
>>>>>>> </key>
>>>>>>> <list-index column="`library_writers_idx`"/>
>>>>>>> <one-to-many entity-name="Writer"/>
>>>>>>> </list>
>>>>>>> <list name="books" lazy="true" cascade="all,delete-orphan">
>>>>>>> <key update="true" foreign-key="library_books">
>>>>>>> <column name="`library_books_e_id`"
>>>>>>> not-null="false" unique="false"/>
>>>>>>> </key>
>>>>>>> <list-index column="`library_books_idx`"/>
>>>>>>> <one-to-many entity-name="Book"/>
>>>>>>> </list>
>>>>>>> </class>
>>>>>>> <class name="org.eclipse.example.library.impl.WriterImpl"
>>>>>>> entity-name="Writer" abstract="false" lazy="true" table="`writer`"
>>>>>>> proxy="org.eclipse.example.library.Writer">
>>>>>>> <meta attribute="eclassName">Writer</meta>
>>>>>>> <meta
>>>>>>> attribute="epackage">http:///org/eclipse/example/library.ecore</meta>
>>>>>>> <id type="long" name="e_id" column="e_id"
>>>>>
>>>
access=" org.eclipse.emf.teneo.hibernate.mapping.identifier.Identifie rPropertyHandler ">
>>>
>>>>>
>>>>>>>
>>>>>>> <meta attribute="syntheticId">true</meta>
>>>>>>> <generator class="native"/>
>>>>>>> </id>
>>>>>>> <version name="e_version" column="e_version"
>>>>>
>>>
access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHandler ">
>>>
>>>>>
>>>>>>>
>>>>>>> <meta attribute="syntheticVersion">true</meta>
>>>>>>> </version>
>>>>>>> <property name="name" lazy="false" insert="true"
>>>>>>> update="true" not-null="false" unique="false"
>>>>>>> type="java.lang.String">
>>>>>>> <column not-null="false" unique="false" name="`name`"/>
>>>>>>> </property>
>>>>>>> <list name="books" table="`writer_books`" lazy="true">
>>>>>>> <key update="true">
>>>>>>> <column name="`writer_e_id`" not-null="true"
>>>>>>> unique="false"/>
>>>>>>> </key>
>>>>>>> <list-index column="`writer_books_idx`"/>
>>>>>>> <many-to-many entity-name="Book" unique="true">
>>>>>>> <column name="`book_e_id`" not-null="true"
>>>>>>> unique="false"/>
>>>>>>> </many-to-many>
>>>>>>> </list>
>>>>>>> </class>
>>>>>>> </hibernate-mapping>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>
>>>
>>>
>>>
>>
>>
Re: [Teneo] hibernate collection lazy loading behavior ? [message #425767 is a reply to message #425765] Mon, 08 December 2008 13:38 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Guillaume,
Ok, the HibernateResource has a getNonResolvingAllContents method which returns an iterator over the
content which should not result in loading non-loaded content. Maybe you can make use of that one in
this case.

gr. Martin

Brocard Guillaume wrote:
> Hi Martin,
>
> I do not understand the 'little triangle' trick. Whenever I click it
> (for collections, I can see a little (rotated yellow) square, no little
> triangle), it is being resolved, as it selects the whole line.
>
> Anyway, your analysis seems to be perfectly correct.
> When displaying the sql queries, I can see that indeed, the initial
> query is just asking for a library. And browsing through the editor
> nodes does lead to new queries, as books and writers should be displayed.
> I've been fooled by the debugging process...
>
> However that still does not work with the extended library example,
> which I am using along with the EMF Transaction framework (my
> application requires that feature). It seems that the transaction change
> recorder is loading the whole resource while adding itself as an adapter
> (at resource loading time).
>
> So Teneo is behaving exactly as expected, thanks a lot for your help
> (and time).
>
> Guillaume.
>
> Martin Taal wrote:
>
>> Hi Stephane, Guillaume,
>> Your test project worked fine. I put a breakpoint in the
>> HibernateResource.
> Then I opened the
>> editor, after stepping through the code I ended up in the method
> loadResource (in HibernateResource)
>> there the content of the resource is loaded in the storeList. When I
>> look in
> the storeList there is
>> one library with two collections books and writers, both
> HibernatePersistableEList.
>
>> Now comes the tricky part: In the variables view I look at the content:
>> - if I click with my mouse on the books or writers (the label) then
> hibernate loads the list (as is
>> visible in the console). The same when I click on the label delegate
>> within
> books/writers. I assume
>> that the debugger forces the list to load by asking for its contents or
> something.
>> - when I however click on the little triangle before the label the debug
> view opens the
>> HibernatePersistableList without loading the list. The same for the
>> little
> triangle before the delegate.
>> - if you do this (open through the triangle) then you will see that
>> the hibernatepersistablelist.delegate has a list member which is null.
>> So this
> means that after the load
>> of the library from the database, the writers and books list have not yet
> been loaded.
>
>> Let me know if you see other behavior.
>
>> gr. Martin
>
>> Martin Taal wrote:
>>> Hi Guillaume Brocard :-),
>>> I received it, I will look at this weekend.
>>>
>>> gr. Martin
>>>
>>> Brocard Guillaume wrote:
>>>> Hi Martin,
>>>>
>>>> Stéphane has just sent you an e-mail with sample projects so as to
>>>> demonstrate the issue (if any).
>>>> We forgot to mention that the connection parameters are declared in
>>>> the activator of the library editor.
>>>>
>>>> Just one last thing, this is using the very simple
>>>> Library/Book/Writer model, with no sub library and no feature map.
>>>>
>>>> Thanks,
>>>> Guillaume.
>>>>
>>>> PS :
>>>> My name is Guillaume. I must have stupidly switched my first name
>>>> and my last name at creation time.
>>>>
>>>> Martin Taal wrote:
>>>>
>>>>> Hi Brocard,
>>>>> Yes I can see what you mean but I would need to debug locally to
>>>>> see what
>>>> goes on. Can you email me
>>>>> a test Eclipse project with a database dump (mysql)? Hibernate libs
>>>>> are not
>>>> needed. Then I can try
>>>>> myself.
>>>>
>>>>> gr. Martin
>>>>
>>>>> Brocard Guillaume wrote:
>>>>>> Hi Martin,
>>>>>>
>>>>>> I'm working with Stéphane on this, and since he can't answer right
>>>>>> now, I'm taking up the torch.
>>>>>>
>>>>>> I have conducted the very same test with the extended library
>>>>>> model (the one with feature map), and basically, the objects
>>>>>> stored in the database are looking like the following tree :
>>>>>>
>>>>>> Library demo
>>>>>> Library NoName
>>>>>> Book book1
>>>>>> Writer writer2
>>>>>> Borrower borrower3
>>>>>> Library library4
>>>>>> Library library5
>>>>>> Book book6
>>>>>> ...
>>>>>> ...
>>>>>> Borrower borrower9999
>>>>>> Book book10000
>>>>>>
>>>>>> So objects are being possessed through libraries, using either the
>>>>>> Library.stock, Library.people, or Library.branches containment
>>>>>> relationships.
>>>>>>
>>>>>> We are using a HibernateResource, with initial query set to :
>>>>>> "SELECT library FROM Library library WHERE library.name='demo'"
>>>>>>
>>>>>> As I debug the loading of my resource (
>>>>>> HibernateResource.loadUsingDefinedQueries(SessionWrapper sess);
>>>>>> line 500) :
>>>>>> final List<?> qryResult = sess.executeQuery(element);
>>>>>> the resulting list does contain Library Demo.
>>>>>>
>>>>>> Unfortunately, its branches list is initialized with Library
>>>>>> NoName, which in turn is initialized with book1, writer2, ...,
>>>>>> library4, ... book10000 all resolved.
>>>>>>
>>>>>> As Stéphane said, that has to do with the hydrated states of the
>>>>>> objects (see Stéphane's explanations).
>>>>>> What are we missing here ?
>>>>>>
>>>>>> Thanks in advance,
>>>>>> Guillaume.
>>>>>>
>>>>>>
>>>>>> Martin Taal wrote:
>>>>>>
>>>>>>> Hi Stéphane,
>>>>>>> I tested this and with me it worked fine.
>>>>>>
>>>>>>> This is for example the mapping for the library.books:
>>>>>>> <list name="books" lazy="true" cascade="all,delete-orphan">
>>>>>>> <key update="true" foreign-key="library_books">
>>>>>>> <column name="`library_books_e_id`"
>>>>>>> not-null="false" unique="false"/>
>>>>>>> </key>
>>>>>>> <list-index column="`library_books_idx`"/>
>>>>>>> <one-to-many entity-name="Book"/>
>>>>>>> </list>
>>>>>>
>>>>>>> and when I get the library it is not loaded:
>>>>>>> Library lib = (Library) res.getContents().get(0);
>>>>>>> only when I do this (in the testcase), the books get loaded:
>>>>>>> assertEquals(3, lib.getBooks().size());
>>>>>>
>>>>>>> Some info, an unloaded Hibernate persistentlist has a list member
>>>>>>> with value
>>>>>> null, if it is loaded
>>>>>>> there will be an arraylist in there.
>>>>>>
>>>>>>> With you the list member of the hibernate persistentlist is set?
>>>>>>
>>>>>>> gr. Martin
>>>>>>
>>>>>>
>>>>>>> Stéphane Fournier wrote:
>>>>>>>> Hi,
>>>>>>>> To continue from the previous post (see
>>>>>>
>>>>
> http://www.eclipse.org/newsportal/article.php?id=37502&g roup=eclipse.tools.emf#37502),
>
>>>>
>>>>>>
>>>>>>>> I failed to load collections lazily. :(
>>>>>>>>
>>>>>>>> I tried with the very simple Library model with 3 classes :
>>>>>>>> Lib
>>>>>>> rary,
>>>>>>>> Book, Writer to avoid FeatureMap collections, Library that
>>>>>>>> contains other ones and so on...
>>>>>>>>
>>>>>>>> I create a root library with a book and its writer.
>>>>>>>>
>>>>>>>> Here the cfg parameters, I use to initialize the HbDataStore
>>>>>>>> (sorry for the code format due to copy/paste in the newsportal) :
>>>>>>>>
>>>>>>>> final Properties props = new Properties();
>>>>>>>> props.setProperty(Environment.DRIVER,
>>>>>>>> "com.mysql.jdbc.Driver");
>>>>>>>> props.setProperty(Environment.USER, "lacarotte");
>>>>>>>> props.setProperty(Environment.URL,
>>>>>>>> "jdbc:mysql://localhost:3306/testOldLibrary");
>>>>>>>> props.setProperty(Environment.PASS, "lcelb");
>>>>>>>> props.setProperty(Environment.DIALECT,
>>>>>>>> org.hibernate.dialect.MySQLInnoDBDialect.class.getName());
>>>>>>>> props.setProperty(Environment.HBM2DDL_AUTO, "update");
>>>>>>>> props.setProperty(Environment.SHOW_SQL,
>>>>>>>> Boolean.TRUE.toString());
>>>>>>>> props.setProperty(Environment.FORMAT_SQL,
>>>>>>>> Boolean.TRUE.toString());
>>>>>>>> props.setProperty(Environment.DEFAULT_BATCH_FETCH_SIZE, "10");
>>>>>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING,
>>>>>>>> "JOINED");
>>>>>>>>
>>>>>>>> props.setProperty(PersistenceOptions.DEFAULT_CACHE_STRATEGY,
>>>>>>>> "NONE");
>>>>>>>> props.setProperty(PersistenceOptions.SET_PROXY,
>>>>>>>> Boolean.TRUE.toString());
>>>>>>>>
>>>>>>>> // Initialize create the HbDataStore
>>>>>>>> HbDataStore hbds =
>>>>>>>> HbHelper.INSTANCE.createRegisterDataStore("library");
>>>>>>>>
>>>>>>>> hbds.setEPackages(new EPackage[] { LibraryPackage.eINSTANCE
>>>>>>>> });
>>>>>>>> hbds.setProperties(props);
>>>>>>>> hbds.initialize();
>>>>>>>>
>>>>>>>> The resource is loaded with topClassesBehavior that runs a query
>>>>>>>> ("from library").
>>>>>>>> I debugged the query execution that returns the root library
>>>>>>>> with its children.
>>>>>>>> At that point, lazy loading failed.
>>>>>>>> The code that loads the children is located in
>>>>>>>> TwoPhaseLoad#initializeEntity(..) (called by
>>>>>>>> QueryLoader#initializeEntitiesAndCollections):
>>>>>>>> Object[] hydratedState = entityEntry.getLoadedState();
>>>>>>>>
>>>>>>>> if ( log.isDebugEnabled() )
>>>>>>>> log.debug("resolving associations for " +
>>>>>>>> MessageHelper.infoString(persister, id, session.getFactory()));
>>>>>>>> Type[] types = persister.getPropertyTypes();
>>>>>>>> for ( int i = 0; i < hydratedState.length; i++ ) {
>>>>>>>> final Object value = hydratedState[i];
>>>>>>>> if ( value!=LazyPropertyInitializer.UNFETCHED_PROPERTY &&
>>>>>>>> value!=BackrefPropertyAccessor.UNKNOWN ) {
>>>>>>>> hydratedState[i] = types[i].resolve( value, session, entity );
>>>>>>>> }
>>>>>>>> }
>>>>>>>> ...
>>>>>>>>
>>>>>>>> The hydratedState array corresponds to my root library. This one
>>>>>>>> contains 2 MarkerObject instances set to NOT_NULL_COLLECTION
>>>>>>>> regarding the 'books' and the 'writers' collections.
>>>>>>>> The call to types[i].resolve( value, session, entity ) when
>>>>>>>> types[i] is such a MarkerObject resolves it as a PersistentList
>>>>>>>> with its data.
>>>>>>>>
>>>>>>>> I would expect a new MarkerObject set to UNFECTCHED_COLLECTION
>>>>>>>> or a not loaded PersistentList (i.e a lazy one).
>>>>>>>>
>>>>>>>> Here is a copy, of the generated hibernate mapping where data
>>>>>>>> are collections are well tagged as lazy ones.
>>>>>>>>
>>>>>>>> Help would be appreciated.
>>>>>>>> Stephane.
>>>>>>>>
>>>>>>>>
>>>>>>>> Mapping content :
>>>>>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>>>>> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate
>>>>>>>> Mapping DTD 3.0//EN"
>>>>>>>> "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
>>>>>>>>
>>>>>>>> <hibernate-mapping auto-import="false">
>>>>>>>> <class name="org.eclipse.example.library.impl.BookImpl"
>>>>>>>> entity-name="Book" abstract="false" lazy="true" table="`book`"
>>>>>>>> proxy="org.eclipse.example.library.Book">
>>>>>>>> <meta attribute="eclassName">Book</meta>
>>>>>>>> <meta
>>>>>>>> attribute="epackage">http:///org/eclipse/example/library.ecore</meta>
>>>>>>>>
>>>>>>>> <id type="long" name="e_id" column="e_id"
>>>>>>
>>>>
> access=" org.eclipse.emf.teneo.hibernate.mapping.identifier.Identifie rPropertyHandler ">
>
>>>>
>>>>>>
>>>>>>>>
>>>>>>>> <meta attribute="syntheticId">true</meta>
>>>>>>>> <generator class="native"/>
>>>>>>>> </id>
>>>>>>>> <version name="e_version" column="e_version"
>>>>>>
>>>>
> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHandler ">
>
>>>>
>>>>>>
>>>>>>>>
>>>>>>>> <meta attribute="syntheticVersion">true</meta>
>>>>>>>> </version>
>>>>>>>> <property name="title" lazy="false" insert="true"
>>>>>>>> update="true" not-null="false" unique="false"
>>>>>>>> type="java.lang.String">
>>>>>>>> <column not-null="false" unique="false"
>>>>>>>> name="`title`"/>
>>>>>>>> </property>
>>>>>>>> <property name="pages" lazy="false" insert="true"
>>>>>>>> update="true" not-null="false" unique="false" type="int">
>>>>>>>> <column not-null="false" unique="false"
>>>>>>>> name="`pages`"/>
>>>>>>>> </property>
>>>>>>>> <property name="category" lazy="false" not-null="false"
>>>>>>>> insert="true" update="true" unique="false">
>>>>>>>> <column not-null="false" unique="false"
>>>>>>>> name="`category`"/>
>>>>>>>> <type
>>>>>>>> name="org.eclipse.emf.teneo.hibernate.mapping.ENumUserType" >
>>>>>>>> <param
>>>>>>>> name="enumClass">org.eclipse.example.library.BookCategory</param >
>>>>>>>> </type>
>>>>>>>> </property>
>>>>>>>> <many-to-one name="author" entity-name="Writer"
>>>>>>>> lazy="proxy" foreign-key="book_author" insert="true"
>>>>>>>> update="true" not-null="false">
>>>>>>>> <column not-null="false" unique="false"
>>>>>>>> name="`book_author_e_id`"/>
>>>>>>>> </many-to-one>
>>>>>>>> </class>
>>>>>>>> <class name="org.eclipse.example.library.impl.LibraryImpl"
>>>>>>>> entity-name="Library" abstract="false" lazy="true"
>>>>>>>> table="`library`" proxy="org.eclipse.example.library.Library">
>>>>>>>> <meta attribute="eclassName">Library</meta>
>>>>>>>> <meta
>>>>>>>> attribute="epackage">http:///org/eclipse/example/library.ecore</meta>
>>>>>>>>
>>>>>>>> <id type="long" name="e_id" column="e_id"
>>>>>>
>>>>
> access=" org.eclipse.emf.teneo.hibernate.mapping.identifier.Identifie rPropertyHandler ">
>
>>>>
>>>>>>
>>>>>>>>
>>>>>>>> <meta attribute="syntheticId">true</meta>
>>>>>>>> <generator class="native"/>
>>>>>>>> </id>
>>>>>>>> <version name="e_version" column="e_version"
>>>>>>
>>>>
> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHandler ">
>
>>>>
>>>>>>
>>>>>>>>
>>>>>>>> <meta attribute="syntheticVersion">true</meta>
>>>>>>>> </version>
>>>>>>>> <property name="name" lazy="false" insert="true"
>>>>>>>> update="true" not-null="false" unique="false"
>>>>>>>> type="java.lang.String">
>>>>>>>> <column not-null="false" unique="false" name="`name`"/>
>>>>>>>> </property>
>>>>>>>> <list name="writers" lazy="true"
>>>>>>>> cascade="all,delete-orphan">
>>>>>>>> <key update="true" foreign-key="library_writers">
>>>>>>>> <column name="`library_writers_e_id`"
>>>>>>>> not-null="false" unique="false"/>
>>>>>>>> </key>
>>>>>>>> <list-index column="`library_writers_idx`"/>
>>>>>>>> <one-to-many entity-name="Writer"/>
>>>>>>>> </list>
>>>>>>>> <list name="books" lazy="true" cascade="all,delete-orphan">
>>>>>>>> <key update="true" foreign-key="library_books">
>>>>>>>> <column name="`library_books_e_id`"
>>>>>>>> not-null="false" unique="false"/>
>>>>>>>> </key>
>>>>>>>> <list-index column="`library_books_idx`"/>
>>>>>>>> <one-to-many entity-name="Book"/>
>>>>>>>> </list>
>>>>>>>> </class>
>>>>>>>> <class name="org.eclipse.example.library.impl.WriterImpl"
>>>>>>>> entity-name="Writer" abstract="false" lazy="true"
>>>>>>>> table="`writer`" proxy="org.eclipse.example.library.Writer">
>>>>>>>> <meta attribute="eclassName">Writer</meta>
>>>>>>>> <meta
>>>>>>>> attribute="epackage">http:///org/eclipse/example/library.ecore</meta>
>>>>>>>>
>>>>>>>> <id type="long" name="e_id" column="e_id"
>>>>>>
>>>>
> access=" org.eclipse.emf.teneo.hibernate.mapping.identifier.Identifie rPropertyHandler ">
>
>>>>
>>>>>>
>>>>>>>>
>>>>>>>> <meta attribute="syntheticId">true</meta>
>>>>>>>> <generator class="native"/>
>>>>>>>> </id>
>>>>>>>> <version name="e_version" column="e_version"
>>>>>>
>>>>
> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHandler ">
>
>>>>
>>>>>>
>>>>>>>>
>>>>>>>> <meta attribute="syntheticVersion">true</meta>
>>>>>>>> </version>
>>>>>>>> <property name="name" lazy="false" insert="true"
>>>>>>>> update="true" not-null="false" unique="false"
>>>>>>>> type="java.lang.String">
>>>>>>>> <column not-null="false" unique="false" name="`name`"/>
>>>>>>>> </property>
>>>>>>>> <list name="books" table="`writer_books`" lazy="true">
>>>>>>>> <key update="true">
>>>>>>>> <column name="`writer_e_id`" not-null="true"
>>>>>>>> unique="false"/>
>>>>>>>> </key>
>>>>>>>> <list-index column="`writer_books_idx`"/>
>>>>>>>> <many-to-many entity-name="Book" unique="true">
>>>>>>>> <column name="`book_e_id`" not-null="true"
>>>>>>>> unique="false"/>
>>>>>>>> </many-to-many>
>>>>>>>> </list>
>>>>>>>> </class>
>>>>>>>> </hibernate-mapping>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>
>
>
>


--

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] hibernate collection lazy loading behavior ? [message #425772 is a reply to message #425767] Mon, 08 December 2008 15:14 Go to previous messageGo to next message
Guillaume Brocard is currently offline Guillaume BrocardFriend
Messages: 25
Registered: July 2009
Junior Member
Martin,

I could try that, providing my own editing domain implementation.
I'll let you know where the thing goes...

Guillaume.

Martin Taal wrote:

> Hi Guillaume,
> Ok, the HibernateResource has a getNonResolvingAllContents method which
returns an iterator over the
> content which should not result in loading non-loaded content. Maybe you can
make use of that one in
> this case.

> gr. Martin

> Brocard Guillaume wrote:
>> Hi Martin,
>>
>> I do not understand the 'little triangle' trick. Whenever I click it
>> (for collections, I can see a little (rotated yellow) square, no little
>> triangle), it is being resolved, as it selects the whole line.
>>
>> Anyway, your analysis seems to be perfectly correct.
>> When displaying the sql queries, I can see that indeed, the initial
>> query is just asking for a library. And browsing through the editor
>> nodes does lead to new queries, as books and writers should be displayed.
>> I've been fooled by the debugging process...
>>
>> However that still does not work with the extended library example,
>> which I am using along with the EMF Transaction framework (my
>> application requires that feature). It seems that the transaction change
>> recorder is loading the whole resource while adding itself as an adapter
>> (at resource loading time).
>>
>> So Teneo is behaving exactly as expected, thanks a lot for your help
>> (and time).
>>
>> Guillaume.
>>
>> Martin Taal wrote:
>>
>>> Hi Stephane, Guillaume,
>>> Your test project worked fine. I put a breakpoint in the
>>> HibernateResource.
>> Then I opened the
>>> editor, after stepping through the code I ended up in the method
>> loadResource (in HibernateResource)
>>> there the content of the resource is loaded in the storeList. When I
>>> look in
>> the storeList there is
>>> one library with two collections books and writers, both
>> HibernatePersistableEList.
>>
>>> Now comes the tricky part: In the variables view I look at the content:
>>> - if I click with my mouse on the books or writers (the label) then
>> hibernate loads the list (as is
>>> visible in the console). The same when I click on the label delegate
>>> within
>> books/writers. I assume
>>> that the debugger forces the list to load by asking for its contents or
>> something.
>>> - when I however click on the little triangle before the label the debug
>> view opens the
>>> HibernatePersistableList without loading the list. The same for the
>>> little
>> triangle before the delegate.
>>> - if you do this (open through the triangle) then you will see that
>>> the hibernatepersistablelist.delegate has a list member which is null.
>>> So this
>> means that after the load
>>> of the library from the database, the writers and books list have not yet
>> been loaded.
>>
>>> Let me know if you see other behavior.
>>
>>> gr. Martin
>>
>>> Martin Taal wrote:
>>>> Hi Guillaume Brocard :-),
>>>> I received it, I will look at this weekend.
>>>>
>>>> gr. Martin
>>>>
>>>> Brocard Guillaume wrote:
>>>>> Hi Martin,
>>>>>
>>>>> Stéphane has just sent you an e-mail with sample projects so as to
>>>>> demonstrate the issue (if any).
>>>>> We forgot to mention that the connection parameters are declared in
>>>>> the activator of the library editor.
>>>>>
>>>>> Just one last thing, this is using the very simple
>>>>> Library/Book/Writer model, with no sub library and no feature map.
>>>>>
>>>>> Thanks,
>>>>> Guillaume.
>>>>>
>>>>> PS :
>>>>> My name is Guillaume. I must have stupidly switched my first name
>>>>> and my last name at creation time.
>>>>>
>>>>> Martin Taal wrote:
>>>>>
>>>>>> Hi Brocard,
>>>>>> Yes I can see what you mean but I would need to debug locally to
>>>>>> see what
>>>>> goes on. Can you email me
>>>>>> a test Eclipse project with a database dump (mysql)? Hibernate libs
>>>>>> are not
>>>>> needed. Then I can try
>>>>>> myself.
>>>>>
>>>>>> gr. Martin
>>>>>
>>>>>> Brocard Guillaume wrote:
>>>>>>> Hi Martin,
>>>>>>>
>>>>>>> I'm working with Stéphane on this, and since he can't answer right
>>>>>>> now, I'm taking up the torch.
>>>>>>>
>>>>>>> I have conducted the very same test with the extended library
>>>>>>> model (the one with feature map), and basically, the objects
>>>>>>> stored in the database are looking like the following tree :
>>>>>>>
>>>>>>> Library demo
>>>>>>> Library NoName
>>>>>>> Book book1
>>>>>>> Writer writer2
>>>>>>> Borrower borrower3
>>>>>>> Library library4
>>>>>>> Library library5
>>>>>>> Book book6
>>>>>>> ...
>>>>>>> ...
>>>>>>> Borrower borrower9999
>>>>>>> Book book10000
>>>>>>>
>>>>>>> So objects are being possessed through libraries, using either the
>>>>>>> Library.stock, Library.people, or Library.branches containment
>>>>>>> relationships.
>>>>>>>
>>>>>>> We are using a HibernateResource, with initial query set to :
>>>>>>> "SELECT library FROM Library library WHERE library.name='demo'"
>>>>>>>
>>>>>>> As I debug the loading of my resource (
>>>>>>> HibernateResource.loadUsingDefinedQueries(SessionWrapper sess);
>>>>>>> line 500) :
>>>>>>> final List<?> qryResult = sess.executeQuery(element);
>>>>>>> the resulting list does contain Library Demo.
>>>>>>>
>>>>>>> Unfortunately, its branches list is initialized with Library
>>>>>>> NoName, which in turn is initialized with book1, writer2, ...,
>>>>>>> library4, ... book10000 all resolved.
>>>>>>>
>>>>>>> As Stéphane said, that has to do with the hydrated states of the
>>>>>>> objects (see Stéphane's explanations).
>>>>>>> What are we missing here ?
>>>>>>>
>>>>>>> Thanks in advance,
>>>>>>> Guillaume.
>>>>>>>
>>>>>>>
>>>>>>> Martin Taal wrote:
>>>>>>>
>>>>>>>> Hi Stéphane,
>>>>>>>> I tested this and with me it worked fine.
>>>>>>>
>>>>>>>> This is for example the mapping for the library.books:
>>>>>>>> <list name="books" lazy="true" cascade="all,delete-orphan">
>>>>>>>> <key update="true" foreign-key="library_books">
>>>>>>>> <column name="`library_books_e_id`"
>>>>>>>> not-null="false" unique="false"/>
>>>>>>>> </key>
>>>>>>>> <list-index column="`library_books_idx`"/>
>>>>>>>> <one-to-many entity-name="Book"/>
>>>>>>>> </list>
>>>>>>>
>>>>>>>> and when I get the library it is not loaded:
>>>>>>>> Library lib = (Library) res.getContents().get(0);
>>>>>>>> only when I do this (in the testcase), the books get loaded:
>>>>>>>> assertEquals(3, lib.getBooks().size());
>>>>>>>
>>>>>>>> Some info, an unloaded Hibernate persistentlist has a list member
>>>>>>>> with value
>>>>>>> null, if it is loaded
>>>>>>>> there will be an arraylist in there.
>>>>>>>
>>>>>>>> With you the list member of the hibernate persistentlist is set?
>>>>>>>
>>>>>>>> gr. Martin
>>>>>>>
>>>>>>>
>>>>>>>> Stéphane Fournier wrote:
>>>>>>>>> Hi,
>>>>>>>>> To continue from the previous post (see
>>>>>>>
>>>>>
>>
http://www.eclipse.org/newsportal/article.php?id=37502&g roup=eclipse.tools.emf#37502),
>>
>>>>>
>>>>>>>
>>>>>>>>> I failed to load collections lazily. :(
>>>>>>>>>
>>>>>>>>> I tried with the very simple Library model with 3 classes :
>>>>>>>>> Lib
>>>>>>>> rary,
>>>>>>>>> Book, Writer to avoid FeatureMap collections, Library that
>>>>>>>>> contains other ones and so on...
>>>>>>>>>
>>>>>>>>> I create a root library with a book and its writer.
>>>>>>>>>
>>>>>>>>> Here the cfg parameters, I use to initialize the HbDataStore
>>>>>>>>> (sorry for the code format due to copy/paste in the newsportal) :
>>>>>>>>>
>>>>>>>>> final Properties props = new Properties();
>>>>>>>>> props.setProperty(Environment.DRIVER,
>>>>>>>>> "com.mysql.jdbc.Driver");
>>>>>>>>> props.setProperty(Environment.USER, "lacarotte");
>>>>>>>>> props.setProperty(Environment.URL,
>>>>>>>>> "jdbc:mysql://localhost:3306/testOldLibrary");
>>>>>>>>> props.setProperty(Environment.PASS, "lcelb");
>>>>>>>>> props.setProperty(Environment.DIALECT,
>>>>>>>>> org.hibernate.dialect.MySQLInnoDBDialect.class.getName());
>>>>>>>>> props.setProperty(Environment.HBM2DDL_AUTO, "update");
>>>>>>>>> props.setProperty(Environment.SHOW_SQL,
>>>>>>>>> Boolean.TRUE.toString());
>>>>>>>>> props.setProperty(Environment.FORMAT_SQL,
>>>>>>>>> Boolean.TRUE.toString());
>>>>>>>>> props.setProperty(Environment.DEFAULT_BATCH_FETCH_SIZE, "10");
>>>>>>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING,
>>>>>>>>> "JOINED");
>>>>>>>>>
>>>>>>>>> props.setProperty(PersistenceOptions.DEFAULT_CACHE_STRATEGY,
>>>>>>>>> "NONE");
>>>>>>>>> props.setProperty(PersistenceOptions.SET_PROXY,
>>>>>>>>> Boolean.TRUE.toString());
>>>>>>>>>
>>>>>>>>> // Initialize create the HbDataStore
>>>>>>>>> HbDataStore hbds =
>>>>>>>>> HbHelper.INSTANCE.createRegisterDataStore("library");
>>>>>>>>>
>>>>>>>>> hbds.setEPackages(new EPackage[] { LibraryPackage.eINSTANCE
>>>>>>>>> });
>>>>>>>>> hbds.setProperties(props);
>>>>>>>>> hbds.initialize();
>>>>>>>>>
>>>>>>>>> The resource is loaded with topClassesBehavior that runs a query
>>>>>>>>> ("from library").
>>>>>>>>> I debugged the query execution that returns the root library
>>>>>>>>> with its children.
>>>>>>>>> At that point, lazy loading failed.
>>>>>>>>> The code that loads the children is located in
>>>>>>>>> TwoPhaseLoad#initializeEntity(..) (called by
>>>>>>>>> QueryLoader#initializeEntitiesAndCollections):
>>>>>>>>> Object[] hydratedState = entityEntry.getLoadedState();
>>>>>>>>>
>>>>>>>>> if ( log.isDebugEnabled() )
>>>>>>>>> log.debug("resolving associations for " +
>>>>>>>>> MessageHelper.infoString(persister, id, session.getFactory()));
>>>>>>>>> Type[] types = persister.getPropertyTypes();
>>>>>>>>> for ( int i = 0; i < hydratedState.length; i++ ) {
>>>>>>>>> final Object value = hydratedState[i];
>>>>>>>>> if ( value!=LazyPropertyInitializer.UNFETCHED_PROPERTY &&
>>>>>>>>> value!=BackrefPropertyAccessor.UNKNOWN ) {
>>>>>>>>> hydratedState[i] = types[i].resolve( value, session, entity );
>>>>>>>>> }
>>>>>>>>> }
>>>>>>>>> ...
>>>>>>>>>
>>>>>>>>> The hydratedState array corresponds to my root library. This one
>>>>>>>>> contains 2 MarkerObject instances set to NOT_NULL_COLLECTION
>>>>>>>>> regarding the 'books' and the 'writers' collections.
>>>>>>>>> The call to types[i].resolve( value, session, entity ) when
>>>>>>>>> types[i] is such a MarkerObject resolves it as a PersistentList
>>>>>>>>> with its data.
>>>>>>>>>
>>>>>>>>> I would expect a new MarkerObject set to UNFECTCHED_COLLECTION
>>>>>>>>> or a not loaded PersistentList (i.e a lazy one).
>>>>>>>>>
>>>>>>>>> Here is a copy, of the generated hibernate mapping where data
>>>>>>>>> are collections are well tagged as lazy ones.
>>>>>>>>>
>>>>>>>>> Help would be appreciated.
>>>>>>>>> Stephane.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Mapping content :
>>>>>>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>>>>>> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate
>>>>>>>>> Mapping DTD 3.0//EN"
>>>>>>>>> "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
>>>>>>>>>
>>>>>>>>> <hibernate-mapping auto-import="false">
>>>>>>>>> <class name="org.eclipse.example.library.impl.BookImpl"
>>>>>>>>> entity-name="Book" abstract="false" lazy="true" table="`book`"
>>>>>>>>> proxy="org.eclipse.example.library.Book">
>>>>>>>>> <meta attribute="eclassName">Book</meta>
>>>>>>>>> <meta
>>>>>>>>>
attribute="epackage">http:///org/eclipse/example/library.ecore</meta>
>>>>>>>>>
>>>>>>>>> <id type="long" name="e_id" column="e_id"
>>>>>>>
>>>>>
>>
access=" org.eclipse.emf.teneo.hibernate.mapping.identifier.Identifie rPropertyHandler ">
>>
>>>>>
>>>>>>>
>>>>>>>>>
>>>>>>>>> <meta attribute="syntheticId">true</meta>
>>>>>>>>> <generator class="native"/>
>>>>>>>>> </id>
>>>>>>>>> <version name="e_version" column="e_version"
>>>>>>>
>>>>>
>>
access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHandler ">
>>
>>>>>
>>>>>>>
>>>>>>>>>
>>>>>>>>> <meta attribute="syntheticVersion">true</meta>
>>>>>>>>> </version>
>>>>>>>>> <property name="title" lazy="false" insert="true"
>>>>>>>>> update="true" not-null="false" unique="false"
>>>>>>>>> type="java.lang.String">
>>>>>>>>> <column not-null="false" unique="false"
>>>>>>>>> name="`title`"/>
>>>>>>>>> </property>
>>>>>>>>> <property name="pages" lazy="false" insert="true"
>>>>>>>>> update="true" not-null="false" unique="false" type="int">
>>>>>>>>> <column not-null="false" unique="false"
>>>>>>>>> name="`pages`"/>
>>>>>>>>> </property>
>>>>>>>>> <property name="category" lazy="false" not-null="false"
>>>>>>>>> insert="true" update="true" unique="false">
>>>>>>>>> <column not-null="false" unique="false"
>>>>>>>>> name="`category`"/>
>>>>>>>>> <type
>>>>>>>>> name="org.eclipse.emf.teneo.hibernate.mapping.ENumUserType" >
>>>>>>>>> <param
>>>>>>>>> name="enumClass">org.eclipse.example.library.BookCategory</param >
>>>>>>>>> </type>
>>>>>>>>> </property>
>>>>>>>>> <many-to-one name="author" entity-name="Writer"
>>>>>>>>> lazy="proxy" foreign-key="book_author" insert="true"
>>>>>>>>> update="true" not-null="false">
>>>>>>>>> <column not-null="false" unique="false"
>>>>>>>>> name="`book_author_e_id`"/>
>>>>>>>>> </many-to-one>
>>>>>>>>> </class>
>>>>>>>>> <class name="org.eclipse.example.library.impl.LibraryImpl"
>>>>>>>>> entity-name="Library" abstract="false" lazy="true"
>>>>>>>>> table="`library`" proxy="org.eclipse.example.library.Library">
>>>>>>>>> <meta attribute="eclassName">Library</meta>
>>>>>>>>> <meta
>>>>>>>>>
attribute="epackage">http:///org/eclipse/example/library.ecore</meta>
>>>>>>>>>
>>>>>>>>> <id type="long" name="e_id" column="e_id"
>>>>>>>
>>>>>
>>
access=" org.eclipse.emf.teneo.hibernate.mapping.identifier.Identifie rPropertyHandler ">
>>
>>>>>
>>>>>>>
>>>>>>>>>
>>>>>>>>> <meta attribute="syntheticId">true</meta>
>>>>>>>>> <generator class="native"/>
>>>>>>>>> </id>
>>>>>>>>> <version name="e_version" column="e_version"
>>>>>>>
>>>>>
>>
access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHandler ">
>>
>>>>>
>>>>>>>
>>>>>>>>>
>>>>>>>>> <meta attribute="syntheticVersion">true</meta>
>>>>>>>>> </version>
>>>>>>>>> <property name="name" lazy="false" insert="true"
>>>>>>>>> update="true" not-null="false" unique="false"
>>>>>>>>> type="java.lang.String">
>>>>>>>>> <column not-null="false" unique="false" name="`name`"/>
>>>>>>>>> </property>
>>>>>>>>> <list name="writers" lazy="true"
>>>>>>>>> cascade="all,delete-orphan">
>>>>>>>>> <key update="true" foreign-key="library_writers">
>>>>>>>>> <column name="`library_writers_e_id`"
>>>>>>>>> not-null="false" unique="false"/>
>>>>>>>>> </key>
>>>>>>>>> <list-index column="`library_writers_idx`"/>
>>>>>>>>> <one-to-many entity-name="Writer"/>
>>>>>>>>> </list>
>>>>>>>>> <list name="books" lazy="true" cascade="all,delete-orphan">
>>>>>>>>> <key update="true" foreign-key="library_books">
>>>>>>>>> <column name="`library_books_e_id`"
>>>>>>>>> not-null="false" unique="false"/>
>>>>>>>>> </key>
>>>>>>>>> <list-index column="`library_books_idx`"/>
>>>>>>>>> <one-to-many entity-name="Book"/>
>>>>>>>>> </list>
>>>>>>>>> </class>
>>>>>>>>> <class name="org.eclipse.example.library.impl.WriterImpl"
>>>>>>>>> entity-name="Writer" abstract="false" lazy="true"
>>>>>>>>> table="`writer`" proxy="org.eclipse.example.library.Writer">
>>>>>>>>> <meta attribute="eclassName">Writer</meta>
>>>>>>>>> <meta
>>>>>>>>>
attribute="epackage">http:///org/eclipse/example/library.ecore</meta>
>>>>>>>>>
>>>>>>>>> <id type="long" name="e_id" column="e_id"
>>>>>>>
>>>>>
>>
access=" org.eclipse.emf.teneo.hibernate.mapping.identifier.Identifie rPropertyHandler ">
>>
>>>>>
>>>>>>>
>>>>>>>>>
>>>>>>>>> <meta attribute="syntheticId">true</meta>
>>>>>>>>> <generator class="native"/>
>>>>>>>>> </id>
>>>>>>>>> <version name="e_version" column="e_version"
>>>>>>>
>>>>>
>>
access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHandler ">
>>
>>>>>
>>>>>>>
>>>>>>>>>
>>>>>>>>> <meta attribute="syntheticVersion">true</meta>
>>>>>>>>> </version>
>>>>>>>>> <property name="name" lazy="false" insert="true"
>>>>>>>>> update="true" not-null="false" unique="false"
>>>>>>>>> type="java.lang.String">
>>>>>>>>> <column not-null="false" unique="false" name="`name`"/>
>>>>>>>>> </property>
>>>>>>>>> <list name="books" table="`writer_books`" lazy="true">
>>>>>>>>> <key update="true">
>>>>>>>>> <column name="`writer_e_id`" not-null="true"
>>>>>>>>> unique="false"/>
>>>>>>>>> </key>
>>>>>>>>> <list-index column="`writer_books_idx`"/>
>>>>>>>>> <many-to-many entity-name="Book" unique="true">
>>>>>>>>> <column name="`book_e_id`" not-null="true"
>>>>>>>>> unique="false"/>
>>>>>>>>> </many-to-many>
>>>>>>>>> </list>
>>>>>>>>> </class>
>>>>>>>>> </hibernate-mapping>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>
>>
>>
>>
Re: [Teneo] hibernate collection lazy loading behavior ? [message #425778 is a reply to message #425772] Mon, 08 December 2008 16:25 Go to previous messageGo to next message
Guillaume Brocard is currently offline Guillaume BrocardFriend
Messages: 25
Registered: July 2009
Junior Member
Hi Martin,

To make a little wrap-up on this issue :
1) I have written my own HibernateResource with
getNonResolvingContent(EObject object_p) just made public.
2) I have provided my own editing domain factory, with one that allows me
to override the change recorder of the newly created transactional editing
domain.
3) Each time the transactional editing domain feels like registering a
change recorder, I'm testing against being a container object. In this
case, I simply return the
myResource.getNonResolvingContent(myRoot).basicIterator() in the change
recorder implementation.

I still have to make sure this is behaving as intended, but loading an
editor on my database content (10 000 objects from the extended library
model) now takes 0.2s when it used to take 24s (on a h2 local database).
It seems like the objects are being resolved when needed only. I can
clearly see that queries are sent while I am exploring the model in the
editor.

That is great news.
Again, thanks a lot for your help.
Guillaume.

Brocard Guillaume wrote:

> Martin,

> I could try that, providing my own editing domain implementation.
> I'll let you know where the thing goes...

> Guillaume.

> Martin Taal wrote:

>> Hi Guillaume,
>> Ok, the HibernateResource has a getNonResolvingAllContents method which
> returns an iterator over the
>> content which should not result in loading non-loaded content. Maybe you
can
> make use of that one in
>> this case.

>> gr. Martin

>> Brocard Guillaume wrote:
>>> Hi Martin,
>>>
>>> I do not understand the 'little triangle' trick. Whenever I click it
>>> (for collections, I can see a little (rotated yellow) square, no little
>>> triangle), it is being resolved, as it selects the whole line.
>>>
>>> Anyway, your analysis seems to be perfectly correct.
>>> When displaying the sql queries, I can see that indeed, the initial
>>> query is just asking for a library. And browsing through the editor
>>> nodes does lead to new queries, as books and writers should be displayed.
>>> I've been fooled by the debugging process...
>>>
>>> However that still does not work with the extended library example,
>>> which I am using along with the EMF Transaction framework (my
>>> application requires that feature). It seems that the transaction change
>>> recorder is loading the whole resource while adding itself as an adapter
>>> (at resource loading time).
>>>
>>> So Teneo is behaving exactly as expected, thanks a lot for your help
>>> (and time).
>>>
>>> Guillaume.
>>>
>>> Martin Taal wrote:
>>>
>>>> Hi Stephane, Guillaume,
>>>> Your test project worked fine. I put a breakpoint in the
>>>> HibernateResource.
>>> Then I opened the
>>>> editor, after stepping through the code I ended up in the method
>>> loadResource (in HibernateResource)
>>>> there the content of the resource is loaded in the storeList. When I
>>>> look in
>>> the storeList there is
>>>> one library with two collections books and writers, both
>>> HibernatePersistableEList.
>>>
>>>> Now comes the tricky part: In the variables view I look at the content:
>>>> - if I click with my mouse on the books or writers (the label) then
>>> hibernate loads the list (as is
>>>> visible in the console). The same when I click on the label delegate
>>>> within
>>> books/writers. I assume
>>>> that the debugger forces the list to load by asking for its contents or
>>> something.
>>>> - when I however click on the little triangle before the label the debug
>>> view opens the
>>>> HibernatePersistableList without loading the list. The same for the
>>>> little
>>> triangle before the delegate.
>>>> - if you do this (open through the triangle) then you will see that
>>>> the hibernatepersistablelist.delegate has a list member which is null.
>>>> So this
>>> means that after the load
>>>> of the library from the database, the writers and books list have not yet
>>> been loaded.
>>>
>>>> Let me know if you see other behavior.
>>>
>>>> gr. Martin
>>>
>>>> Martin Taal wrote:
>>>>> Hi Guillaume Brocard :-),
>>>>> I received it, I will look at this weekend.
>>>>>
>>>>> gr. Martin
>>>>>
>>>>> Brocard Guillaume wrote:
>>>>>> Hi Martin,
>>>>>>
>>>>>> Stéphane has just sent you an e-mail with sample projects so as to
>>>>>> demonstrate the issue (if any).
>>>>>> We forgot to mention that the connection parameters are declared in
>>>>>> the activator of the library editor.
>>>>>>
>>>>>> Just one last thing, this is using the very simple
>>>>>> Library/Book/Writer model, with no sub library and no feature map.
>>>>>>
>>>>>> Thanks,
>>>>>> Guillaume.
>>>>>>
>>>>>> PS :
>>>>>> My name is Guillaume. I must have stupidly switched my first name
>>>>>> and my last name at creation time.
>>>>>>
>>>>>> Martin Taal wrote:
>>>>>>
>>>>>>> Hi Brocard,
>>>>>>> Yes I can see what you mean but I would need to debug locally to
>>>>>>> see what
>>>>>> goes on. Can you email me
>>>>>>> a test Eclipse project with a database dump (mysql)? Hibernate libs
>>>>>>> are not
>>>>>> needed. Then I can try
>>>>>>> myself.
>>>>>>
>>>>>>> gr. Martin
>>>>>>
>>>>>>> Brocard Guillaume wrote:
>>>>>>>> Hi Martin,
>>>>>>>>
>>>>>>>> I'm working with Stéphane on this, and since he can't answer right
>>>>>>>> now, I'm taking up the torch.
>>>>>>>>
>>>>>>>> I have conducted the very same test with the extended library
>>>>>>>> model (the one with feature map), and basically, the objects
>>>>>>>> stored in the database are looking like the following tree :
>>>>>>>>
>>>>>>>> Library demo
>>>>>>>> Library NoName
>>>>>>>> Book book1
>>>>>>>> Writer writer2
>>>>>>>> Borrower borrower3
>>>>>>>> Library library4
>>>>>>>> Library library5
>>>>>>>> Book book6
>>>>>>>> ...
>>>>>>>> ...
>>>>>>>> Borrower borrower9999
>>>>>>>> Book book10000
>>>>>>>>
>>>>>>>> So objects are being possessed through libraries, using either the
>>>>>>>> Library.stock, Library.people, or Library.branches containment
>>>>>>>> relationships.
>>>>>>>>
>>>>>>>> We are using a HibernateResource, with initial query set to :
>>>>>>>> "SELECT library FROM Library library WHERE library.name='demo'"
>>>>>>>>
>>>>>>>> As I debug the loading of my resource (
>>>>>>>> HibernateResource.loadUsingDefinedQueries(SessionWrapper sess);
>>>>>>>> line 500) :
>>>>>>>> final List<?> qryResult = sess.executeQuery(element);
>>>>>>>> the resulting list does contain Library Demo.
>>>>>>>>
>>>>>>>> Unfortunately, its branches list is initialized with Library
>>>>>>>> NoName, which in turn is initialized with book1, writer2, ...,
>>>>>>>> library4, ... book10000 all resolved.
>>>>>>>>
>>>>>>>> As Stéphane said, that has to do with the hydrated states of the
>>>>>>>> objects (see Stéphane's explanations).
>>>>>>>> What are we missing here ?
>>>>>>>>
>>>>>>>> Thanks in advance,
>>>>>>>> Guillaume.
>>>>>>>>
>>>>>>>>
>>>>>>>> Martin Taal wrote:
>>>>>>>>
>>>>>>>>> Hi Stéphane,
>>>>>>>>> I tested this and with me it worked fine.
>>>>>>>>
>>>>>>>>> This is for example the mapping for the library.books:
>>>>>>>>> <list name="books" lazy="true" cascade="all,delete-orphan">
>>>>>>>>> <key update="true" foreign-key="library_books">
>>>>>>>>> <column name="`library_books_e_id`"
>>>>>>>>> not-null="false" unique="false"/>
>>>>>>>>> </key>
>>>>>>>>> <list-index column="`library_books_idx`"/>
>>>>>>>>> <one-to-many entity-name="Book"/>
>>>>>>>>> </list>
>>>>>>>>
>>>>>>>>> and when I get the library it is not loaded:
>>>>>>>>> Library lib = (Library) res.getContents().get(0);
>>>>>>>>> only when I do this (in the testcase), the books get loaded:
>>>>>>>>> assertEquals(3, lib.getBooks().size());
>>>>>>>>
>>>>>>>>> Some info, an unloaded Hibernate persistentlist has a list member
>>>>>>>>> with value
>>>>>>>> null, if it is loaded
>>>>>>>>> there will be an arraylist in there.
>>>>>>>>
>>>>>>>>> With you the list member of the hibernate persistentlist is set?
>>>>>>>>
>>>>>>>>> gr. Martin
>>>>>>>>
>>>>>>>>
>>>>>>>>> Stéphane Fournier wrote:
>>>>>>>>>> Hi,
>>>>>>>>>> To continue from the previous post (see
>>>>>>>>
>>>>>>
>>>
>
http://www.eclipse.org/newsportal/article.php?id=37502&g roup=eclipse.tools.emf#37502),
>>>
>>>>>>
>>>>>>>>
>>>>>>>>>> I failed to load collections lazily. :(
>>>>>>>>>>
>>>>>>>>>> I tried with the very simple Library model with 3 classes :
>>>>>>>>>> Lib
>>>>>>>>> rary,
>>>>>>>>>> Book, Writer to avoid FeatureMap collections, Library that
>>>>>>>>>> contains other ones and so on...
>>>>>>>>>>
>>>>>>>>>> I create a root library with a book and its writer.
>>>>>>>>>>
>>>>>>>>>> Here the cfg parameters, I use to initialize the HbDataStore
>>>>>>>>>> (sorry for the code format due to copy/paste in the newsportal) :
>>>>>>>>>>
>>>>>>>>>> final Properties props = new Properties();
>>>>>>>>>> props.setProperty(Environment.DRIVER,
>>>>>>>>>> "com.mysql.jdbc.Driver");
>>>>>>>>>> props.setProperty(Environment.USER, "lacarotte");
>>>>>>>>>> props.setProperty(Environment.URL,
>>>>>>>>>> "jdbc:mysql://localhost:3306/testOldLibrary");
>>>>>>>>>> props.setProperty(Environment.PASS, "lcelb");
>>>>>>>>>> props.setProperty(Environment.DIALECT,
>>>>>>>>>> org.hibernate.dialect.MySQLInnoDBDialect.class.getName());
>>>>>>>>>> props.setProperty(Environment.HBM2DDL_AUTO, "update");
>>>>>>>>>> props.setProperty(Environment.SHOW_SQL,
>>>>>>>>>> Boolean.TRUE.toString());
>>>>>>>>>> props.setProperty(Environment.FORMAT_SQL,
>>>>>>>>>> Boolean.TRUE.toString());
>>>>>>>>>> props.setProperty(Environment.DEFAULT_BATCH_FETCH_SIZE, "10");
>>>>>>>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING,
>>>>>>>>>> "JOINED");
>>>>>>>>>>
>>>>>>>>>> props.setProperty(PersistenceOptions.DEFAULT_CACHE_STRATEGY,
>>>>>>>>>> "NONE");
>>>>>>>>>> props.setProperty(PersistenceOptions.SET_PROXY,
>>>>>>>>>> Boolean.TRUE.toString());
>>>>>>>>>>
>>>>>>>>>> // Initialize create the HbDataStore
>>>>>>>>>> HbDataStore hbds =
>>>>>>>>>> HbHelper.INSTANCE.createRegisterDataStore("library");
>>>>>>>>>>
>>>>>>>>>> hbds.setEPackages(new EPackage[] { LibraryPackage.eINSTANCE
>>>>>>>>>> });
>>>>>>>>>> hbds.setProperties(props);
>>>>>>>>>> hbds.initialize();
>>>>>>>>>>
>>>>>>>>>> The resource is loaded with topClassesBehavior that runs a query
>>>>>>>>>> ("from library").
>>>>>>>>>> I debugged the query execution that returns the root library
>>>>>>>>>> with its children.
>>>>>>>>>> At that point, lazy loading failed.
>>>>>>>>>> The code that loads the children is located in
>>>>>>>>>> TwoPhaseLoad#initializeEntity(..) (called by
>>>>>>>>>> QueryLoader#initializeEntitiesAndCollections):
>>>>>>>>>> Object[] hydratedState = entityEntry.getLoadedState();
>>>>>>>>>>
>>>>>>>>>> if ( log.isDebugEnabled() )
>>>>>>>>>> log.debug("resolving associations for " +
>>>>>>>>>> MessageHelper.infoString(persister, id, session.getFactory()));
>>>>>>>>>> Type[] types = persister.getPropertyTypes();
>>>>>>>>>> for ( int i = 0; i < hydratedState.length; i++ ) {
>>>>>>>>>> final Object value = hydratedState[i];
>>>>>>>>>> if ( value!=LazyPropertyInitializer.UNFETCHED_PROPERTY &&
>>>>>>>>>> value!=BackrefPropertyAccessor.UNKNOWN ) {
>>>>>>>>>> hydratedState[i] = types[i].resolve( value, session, entity );
>>>>>>>>>> }
>>>>>>>>>> }
>>>>>>>>>> ...
>>>>>>>>>>
>>>>>>>>>> The hydratedState array corresponds to my root library. This one
>>>>>>>>>> contains 2 MarkerObject instances set to NOT_NULL_COLLECTION
>>>>>>>>>> regarding the 'books' and the 'writers' collections.
>>>>>>>>>> The call to types[i].resolve( value, session, entity ) when
>>>>>>>>>> types[i] is such a MarkerObject resolves it as a PersistentList
>>>>>>>>>> with its data.
>>>>>>>>>>
>>>>>>>>>> I would expect a new MarkerObject set to UNFECTCHED_COLLECTION
>>>>>>>>>> or a not loaded PersistentList (i.e a lazy one).
>>>>>>>>>>
>>>>>>>>>> Here is a copy, of the generated hibernate mapping where data
>>>>>>>>>> are collections are well tagged as lazy ones.
>>>>>>>>>>
>>>>>>>>>> Help would be appreciated.
>>>>>>>>>> Stephane.
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Mapping content :
>>>>>>>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>>>>>>> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate
>>>>>>>>>> Mapping DTD 3.0//EN"
>>>>>>>>>> "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
>>>>>>>>>>
>>>>>>>>>> <hibernate-mapping auto-import="false">
>>>>>>>>>> <class name="org.eclipse.example.library.impl.BookImpl"
>>>>>>>>>> entity-name="Book" abstract="false" lazy="true" table="`book`"
>>>>>>>>>> proxy="org.eclipse.example.library.Book">
>>>>>>>>>> <meta attribute="eclassName">Book</meta>
>>>>>>>>>> <meta
>>>>>>>>>>
> attribute="epackage">http:///org/eclipse/example/library.ecore</meta>
>>>>>>>>>>
>>>>>>>>>> <id type="long" name="e_id" column="e_id"
>>>>>>>>
>>>>>>
>>>
>
access=" org.eclipse.emf.teneo.hibernate.mapping.identifier.Identifie rPropertyHandler ">
>>>
>>>>>>
>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> <meta attribute="syntheticId">true</meta>
>>>>>>>>>> <generator class="native"/>
>>>>>>>>>> </id>
>>>>>>>>>> <version name="e_version" column="e_version"
>>>>>>>>
>>>>>>
>>>
>
access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHandler ">
>>>
>>>>>>
>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> <meta attribute="syntheticVersion">true</meta>
>>>>>>>>>> </version>
>>>>>>>>>> <property name="title" lazy="false" insert="true"
>>>>>>>>>> update="true" not-null="false" unique="false"
>>>>>>>>>> type="java.lang.String">
>>>>>>>>>> <column not-null="false" unique="false"
>>>>>>>>>> name="`title`"/>
>>>>>>>>>> </property>
>>>>>>>>>> <property name="pages" lazy="false" insert="true"
>>>>>>>>>> update="true" not-null="false" unique="false" type="int">
>>>>>>>>>> <column not-null="false" unique="false"
>>>>>>>>>> name="`pages`"/>
>>>>>>>>>> </property>
>>>>>>>>>> <property name="category" lazy="false" not-null="false"
>>>>>>>>>> insert="true" update="true" unique="false">
>>>>>>>>>> <column not-null="false" unique="false"
>>>>>>>>>> name="`category`"/>
>>>>>>>>>> <type
>>>>>>>>>> name="org.eclipse.emf.teneo.hibernate.mapping.ENumUserType" >
>>>>>>>>>> <param
>>>>>>>>>> name="enumClass">org.eclipse.example.library.BookCategory</param >
>>>>>>>>>> </type>
>>>>>>>>>> </property>
>>>>>>>>>> <many-to-one name="author" entity-name="Writer"
>>>>>>>>>> lazy="proxy" foreign-key="book_author" insert="true"
>>>>>>>>>> update="true" not-null="false">
>>>>>>>>>> <column not-null="false" unique="false"
>>>>>>>>>> name="`book_author_e_id`"/>
>>>>>>>>>> </many-to-one>
>>>>>>>>>> </class>
>>>>>>>>>> <class name="org.eclipse.example.library.impl.LibraryImpl"
>>>>>>>>>> entity-name="Library" abstract="false" lazy="true"
>>>>>>>>>> table="`library`" proxy="org.eclipse.example.library.Library">
>>>>>>>>>> <meta attribute="eclassName">Library</meta>
>>>>>>>>>> <meta
>>>>>>>>>>
> attribute="epackage">http:///org/eclipse/example/library.ecore</meta>
>>>>>>>>>>
>>>>>>>>>> <id type="long" name="e_id" column="e_id"
>>>>>>>>
>>>>>>
>>>
>
access=" org.eclipse.emf.teneo.hibernate.mapping.identifier.Identifie rPropertyHandler ">
>>>
>>>>>>
>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> <meta attribute="syntheticId">true</meta>
>>>>>>>>>> <generator class="native"/>
>>>>>>>>>> </id>
>>>>>>>>>> <version name="e_version" column="e_version"
>>>>>>>>
>>>>>>
>>>
>
access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHandler ">
>>>
>>>>>>
>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> <meta attribute="syntheticVersion">true</meta>
>>>>>>>>>> </version>
>>>>>>>>>> <property name="name" lazy="false" insert="true"
>>>>>>>>>> update="true" not-null="false" unique="false"
>>>>>>>>>> type="java.lang.String">
>>>>>>>>>> <column not-null="false" unique="false" name="`name`"/>
>>>>>>>>>> </property>
>>>>>>>>>> <list name="writers" lazy="true"
>>>>>>>>>> cascade="all,delete-orphan">
>>>>>>>>>> <key update="true" foreign-key="library_writers">
>>>>>>>>>> <column name="`library_writers_e_id`"
>>>>>>>>>> not-null="false" unique="false"/>
>>>>>>>>>> </key>
>>>>>>>>>> <list-index column="`library_writers_idx`"/>
>>>>>>>>>> <one-to-many entity-name="Writer"/>
>>>>>>>>>> </list>
>>>>>>>>>> <list name="books" lazy="true" cascade="all,delete-orphan">
>>>>>>>>>> <key update="true" foreign-key="library_books">
>>>>>>>>>> <column name="`library_books_e_id`"
>>>>>>>>>> not-null="false" unique="false"/>
>>>>>>>>>> </key>
>>>>>>>>>> <list-index column="`library_books_idx`"/>
>>>>>>>>>> <one-to-many entity-name="Book"/>
>>>>>>>>>> </list>
>>>>>>>>>> </class>
>>>>>>>>>> <class name="org.eclipse.example.library.impl.WriterImpl"
>>>>>>>>>> entity-name="Writer" abstract="false" lazy="true"
>>>>>>>>>> table="`writer`" proxy="org.eclipse.example.library.Writer">
>>>>>>>>>> <meta attribute="eclassName">Writer</meta>
>>>>>>>>>> <meta
>>>>>>>>>>
> attribute="epackage">http:///org/eclipse/example/library.ecore</meta>
>>>>>>>>>>
>>>>>>>>>> <id type="long" name="e_id" column="e_id"
>>>>>>>>
>>>>>>
>>>
>
access=" org.eclipse.emf.teneo.hibernate.mapping.identifier.Identifie rPropertyHandler ">
>>>
>>>>>>
>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> <meta attribute="syntheticId">true</meta>
>>>>>>>>>> <generator class="native"/>
>>>>>>>>>> </id>
>>>>>>>>>> <version name="e_version" column="e_version"
>>>>>>>>
>>>>>>
>>>
>
access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHandler ">
>>>
>>>>>>
>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> <meta attribute="syntheticVersion">true</meta>
>>>>>>>>>> </version>
>>>>>>>>>> <property name="name" lazy="false" insert="true"
>>>>>>>>>> update="true" not-null="false" unique="false"
>>>>>>>>>> type="java.lang.String">
>>>>>>>>>> <column not-null="false" unique="false" name="`name`"/>
>>>>>>>>>> </property>
>>>>>>>>>> <list name="books" table="`writer_books`" lazy="true">
>>>>>>>>>> <key update="true">
>>>>>>>>>> <column name="`writer_e_id`" not-null="true"
>>>>>>>>>> unique="false"/>
>>>>>>>>>> </key>
>>>>>>>>>> <list-index column="`writer_books_idx`"/>
>>>>>>>>>> <many-to-many entity-name="Book" unique="true">
>>>>>>>>>> <column name="`book_e_id`" not-null="true"
>>>>>>>>>> unique="false"/>
>>>>>>>>>> </many-to-many>
>>>>>>>>>> </list>
>>>>>>>>>> </class>
>>>>>>>>>> </hibernate-mapping>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>
>>>
>>>
>>>
Re: [Teneo] hibernate collection lazy loading behavior ? [message #425780 is a reply to message #425778] Mon, 08 December 2008 16:29 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Guillaume,
Thanks for the update and good to hear that it works better.

gr. Martin

Brocard Guillaume wrote:
> Hi Martin,
>
> To make a little wrap-up on this issue :
> 1) I have written my own HibernateResource with
> getNonResolvingContent(EObject object_p) just made public.
> 2) I have provided my own editing domain factory, with one that allows
> me to override the change recorder of the newly created transactional
> editing domain.
> 3) Each time the transactional editing domain feels like registering a
> change recorder, I'm testing against being a container object. In this
> case, I simply return the
> myResource.getNonResolvingContent(myRoot).basicIterator() in the change
> recorder implementation.
>
> I still have to make sure this is behaving as intended, but loading an
> editor on my database content (10 000 objects from the extended library
> model) now takes 0.2s when it used to take 24s (on a h2 local database).
> It seems like the objects are being resolved when needed only. I can
> clearly see that queries are sent while I am exploring the model in the
> editor.
>
> That is great news.
> Again, thanks a lot for your help.
> Guillaume.
>
> Brocard Guillaume wrote:
>
>> Martin,
>
>> I could try that, providing my own editing domain implementation.
>> I'll let you know where the thing goes...
>
>> Guillaume.
>
>> Martin Taal wrote:
>
>>> Hi Guillaume,
>>> Ok, the HibernateResource has a getNonResolvingAllContents method which
>> returns an iterator over the
>>> content which should not result in loading non-loaded content. Maybe you
> can
>> make use of that one in
>>> this case.
>
>>> gr. Martin
>
>>> Brocard Guillaume wrote:
>>>> Hi Martin,
>>>>
>>>> I do not understand the 'little triangle' trick. Whenever I click it
>>>> (for collections, I can see a little (rotated yellow) square, no
>>>> little triangle), it is being resolved, as it selects the whole line.
>>>>
>>>> Anyway, your analysis seems to be perfectly correct.
>>>> When displaying the sql queries, I can see that indeed, the initial
>>>> query is just asking for a library. And browsing through the editor
>>>> nodes does lead to new queries, as books and writers should be
>>>> displayed.
>>>> I've been fooled by the debugging process...
>>>>
>>>> However that still does not work with the extended library example,
>>>> which I am using along with the EMF Transaction framework (my
>>>> application requires that feature). It seems that the transaction
>>>> change recorder is loading the whole resource while adding itself as
>>>> an adapter (at resource loading time).
>>>>
>>>> So Teneo is behaving exactly as expected, thanks a lot for your help
>>>> (and time).
>>>>
>>>> Guillaume.
>>>>
>>>> Martin Taal wrote:
>>>>
>>>>> Hi Stephane, Guillaume,
>>>>> Your test project worked fine. I put a breakpoint in the
>>>>> HibernateResource.
>>>> Then I opened the
>>>>> editor, after stepping through the code I ended up in the method
>>>> loadResource (in HibernateResource)
>>>>> there the content of the resource is loaded in the storeList. When
>>>>> I look in
>>>> the storeList there is
>>>>> one library with two collections books and writers, both
>>>> HibernatePersistableEList.
>>>>
>>>>> Now comes the tricky part: In the variables view I look at the
>>>>> content:
>>>>> - if I click with my mouse on the books or writers (the label) then
>>>> hibernate loads the list (as is
>>>>> visible in the console). The same when I click on the label
>>>>> delegate within
>>>> books/writers. I assume
>>>>> that the debugger forces the list to load by asking for its
>>>>> contents or
>>>> something.
>>>>> - when I however click on the little triangle before the label the
>>>>> debug
>>>> view opens the
>>>>> HibernatePersistableList without loading the list. The same for the
>>>>> little
>>>> triangle before the delegate.
>>>>> - if you do this (open through the triangle) then you will see that
>>>>> the hibernatepersistablelist.delegate has a list member which is
>>>>> null. So this
>>>> means that after the load
>>>>> of the library from the database, the writers and books list have
>>>>> not yet
>>>> been loaded.
>>>>
>>>>> Let me know if you see other behavior.
>>>>
>>>>> gr. Martin
>>>>
>>>>> Martin Taal wrote:
>>>>>> Hi Guillaume Brocard :-),
>>>>>> I received it, I will look at this weekend.
>>>>>>
>>>>>> gr. Martin
>>>>>>
>>>>>> Brocard Guillaume wrote:
>>>>>>> Hi Martin,
>>>>>>>
>>>>>>> Stéphane has just sent you an e-mail with sample projects so as
>>>>>>> to demonstrate the issue (if any).
>>>>>>> We forgot to mention that the connection parameters are declared
>>>>>>> in the activator of the library editor.
>>>>>>>
>>>>>>> Just one last thing, this is using the very simple
>>>>>>> Library/Book/Writer model, with no sub library and no feature map.
>>>>>>>
>>>>>>> Thanks,
>>>>>>> Guillaume.
>>>>>>>
>>>>>>> PS :
>>>>>>> My name is Guillaume. I must have stupidly switched my first name
>>>>>>> and my last name at creation time.
>>>>>>>
>>>>>>> Martin Taal wrote:
>>>>>>>
>>>>>>>> Hi Brocard,
>>>>>>>> Yes I can see what you mean but I would need to debug locally to
>>>>>>>> see what
>>>>>>> goes on. Can you email me
>>>>>>>> a test Eclipse project with a database dump (mysql)? Hibernate
>>>>>>>> libs are not
>>>>>>> needed. Then I can try
>>>>>>>> myself.
>>>>>>>
>>>>>>>> gr. Martin
>>>>>>>
>>>>>>>> Brocard Guillaume wrote:
>>>>>>>>> Hi Martin,
>>>>>>>>>
>>>>>>>>> I'm working with Stéphane on this, and since he can't answer
>>>>>>>>> right now, I'm taking up the torch.
>>>>>>>>>
>>>>>>>>> I have conducted the very same test with the extended library
>>>>>>>>> model (the one with feature map), and basically, the objects
>>>>>>>>> stored in the database are looking like the following tree :
>>>>>>>>>
>>>>>>>>> Library demo
>>>>>>>>> Library NoName
>>>>>>>>> Book book1
>>>>>>>>> Writer writer2
>>>>>>>>> Borrower borrower3
>>>>>>>>> Library library4
>>>>>>>>> Library library5
>>>>>>>>> Book book6
>>>>>>>>> ...
>>>>>>>>> ...
>>>>>>>>> Borrower borrower9999
>>>>>>>>> Book book10000
>>>>>>>>>
>>>>>>>>> So objects are being possessed through libraries, using either
>>>>>>>>> the Library.stock, Library.people, or Library.branches
>>>>>>>>> containment relationships.
>>>>>>>>>
>>>>>>>>> We are using a HibernateResource, with initial query set to :
>>>>>>>>> "SELECT library FROM Library library WHERE library.name='demo'"
>>>>>>>>>
>>>>>>>>> As I debug the loading of my resource (
>>>>>>>>> HibernateResource.loadUsingDefinedQueries(SessionWrapper sess);
>>>>>>>>> line 500) :
>>>>>>>>> final List<?> qryResult = sess.executeQuery(element);
>>>>>>>>> the resulting list does contain Library Demo.
>>>>>>>>>
>>>>>>>>> Unfortunately, its branches list is initialized with Library
>>>>>>>>> NoName, which in turn is initialized with book1, writer2, ...,
>>>>>>>>> library4, ... book10000 all resolved.
>>>>>>>>>
>>>>>>>>> As Stéphane said, that has to do with the hydrated states of
>>>>>>>>> the objects (see Stéphane's explanations).
>>>>>>>>> What are we missing here ?
>>>>>>>>>
>>>>>>>>> Thanks in advance,
>>>>>>>>> Guillaume.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Martin Taal wrote:
>>>>>>>>>
>>>>>>>>>> Hi Stéphane,
>>>>>>>>>> I tested this and with me it worked fine.
>>>>>>>>>
>>>>>>>>>> This is for example the mapping for the library.books:
>>>>>>>>>> <list name="books" lazy="true"
>>>>>>>>>> cascade="all,delete-orphan">
>>>>>>>>>> <key update="true" foreign-key="library_books">
>>>>>>>>>> <column name="`library_books_e_id`"
>>>>>>>>>> not-null="false" unique="false"/>
>>>>>>>>>> </key>
>>>>>>>>>> <list-index column="`library_books_idx`"/>
>>>>>>>>>> <one-to-many entity-name="Book"/>
>>>>>>>>>> </list>
>>>>>>>>>
>>>>>>>>>> and when I get the library it is not loaded:
>>>>>>>>>> Library lib = (Library) res.getContents().get(0);
>>>>>>>>>> only when I do this (in the testcase), the books get loaded:
>>>>>>>>>> assertEquals(3, lib.getBooks().size());
>>>>>>>>>
>>>>>>>>>> Some info, an unloaded Hibernate persistentlist has a list
>>>>>>>>>> member with value
>>>>>>>>> null, if it is loaded
>>>>>>>>>> there will be an arraylist in there.
>>>>>>>>>
>>>>>>>>>> With you the list member of the hibernate persistentlist is set?
>>>>>>>>>
>>>>>>>>>> gr. Martin
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>> Stéphane Fournier wrote:
>>>>>>>>>>> Hi,
>>>>>>>>>>> To continue from the previous post (see
>>>>>>>>>
>>>>>>>
>>>>
>>
> http://www.eclipse.org/newsportal/article.php?id=37502&g roup=eclipse.tools.emf#37502),
>
>>>>
>>>>>>>
>>>>>>>>>
>>>>>>>>>>> I failed to load collections lazily. :(
>>>>>>>>>>>
>>>>>>>>>>> I tried with the very simple Library model with 3 classes :
>>>>>>>>>>> Lib
>>>>>>>>>> rary,
>>>>>>>>>>> Book, Writer to avoid FeatureMap collections, Library that
>>>>>>>>>>> contains other ones and so on...
>>>>>>>>>>>
>>>>>>>>>>> I create a root library with a book and its writer.
>>>>>>>>>>>
>>>>>>>>>>> Here the cfg parameters, I use to initialize the HbDataStore
>>>>>>>>>>> (sorry for the code format due to copy/paste in the
>>>>>>>>>>> newsportal) :
>>>>>>>>>>>
>>>>>>>>>>> final Properties props = new Properties();
>>>>>>>>>>> props.setProperty(Environment.DRIVER,
>>>>>>>>>>> "com.mysql.jdbc.Driver");
>>>>>>>>>>> props.setProperty(Environment.USER, "lacarotte");
>>>>>>>>>>> props.setProperty(Environment.URL,
>>>>>>>>>>> "jdbc:mysql://localhost:3306/testOldLibrary");
>>>>>>>>>>> props.setProperty(Environment.PASS, "lcelb");
>>>>>>>>>>> props.setProperty(Environment.DIALECT,
>>>>>>>>>>> org.hibernate.dialect.MySQLInnoDBDialect.class.getName());
>>>>>>>>>>> props.setProperty(Environment.HBM2DDL_AUTO, "update");
>>>>>>>>>>> props.setProperty(Environment.SHOW_SQL,
>>>>>>>>>>> Boolean.TRUE.toString());
>>>>>>>>>>> props.setProperty(Environment.FORMAT_SQL,
>>>>>>>>>>> Boolean.TRUE.toString());
>>>>>>>>>>> props.setProperty(Environment.DEFAULT_BATCH_FETCH_SIZE,
>>>>>>>>>>> "10");
>>>>>>>>>>>
>>>>>>>>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING,
>>>>>>>>>>> "JOINED");
>>>>>>>>>>>
>>>>>>>>>>> props.setProperty(PersistenceOptions.DEFAULT_CACHE_STRATEGY,
>>>>>>>>>>> "NONE");
>>>>>>>>>>> props.setProperty(PersistenceOptions.SET_PROXY,
>>>>>>>>>>> Boolean.TRUE.toString());
>>>>>>>>>>>
>>>>>>>>>>> // Initialize create the HbDataStore
>>>>>>>>>>> HbDataStore hbds =
>>>>>>>>>>> HbHelper.INSTANCE.createRegisterDataStore("library");
>>>>>>>>>>>
>>>>>>>>>>> hbds.setEPackages(new EPackage[] {
>>>>>>>>>>> LibraryPackage.eINSTANCE });
>>>>>>>>>>> hbds.setProperties(props);
>>>>>>>>>>> hbds.initialize();
>>>>>>>>>>>
>>>>>>>>>>> The resource is loaded with topClassesBehavior that runs a
>>>>>>>>>>> query ("from library").
>>>>>>>>>>> I debugged the query execution that returns the root library
>>>>>>>>>>> with its children.
>>>>>>>>>>> At that point, lazy loading failed.
>>>>>>>>>>> The code that loads the children is located in
>>>>>>>>>>> TwoPhaseLoad#initializeEntity(..) (called by
>>>>>>>>>>> QueryLoader#initializeEntitiesAndCollections):
>>>>>>>>>>> Object[] hydratedState = entityEntry.getLoadedState();
>>>>>>>>>>>
>>>>>>>>>>> if ( log.isDebugEnabled() )
>>>>>>>>>>> log.debug("resolving associations for " +
>>>>>>>>>>> MessageHelper.infoString(persister, id, session.getFactory()));
>>>>>>>>>>> Type[] types = persister.getPropertyTypes();
>>>>>>>>>>> for ( int i = 0; i < hydratedState.length; i++ ) {
>>>>>>>>>>> final Object value = hydratedState[i];
>>>>>>>>>>> if ( value!=LazyPropertyInitializer.UNFETCHED_PROPERTY &&
>>>>>>>>>>> value!=BackrefPropertyAccessor.UNKNOWN ) {
>>>>>>>>>>> hydratedState[i] = types[i].resolve( value, session,
>>>>>>>>>>> entity );
>>>>>>>>>>> }
>>>>>>>>>>> }
>>>>>>>>>>> ...
>>>>>>>>>>>
>>>>>>>>>>> The hydratedState array corresponds to my root library. This
>>>>>>>>>>> one contains 2 MarkerObject instances set to
>>>>>>>>>>> NOT_NULL_COLLECTION regarding the 'books' and the 'writers'
>>>>>>>>>>> collections.
>>>>>>>>>>> The call to types[i].resolve( value, session, entity ) when
>>>>>>>>>>> types[i] is such a MarkerObject resolves it as a
>>>>>>>>>>> PersistentList with its data.
>>>>>>>>>>>
>>>>>>>>>>> I would expect a new MarkerObject set to
>>>>>>>>>>> UNFECTCHED_COLLECTION or a not loaded PersistentList (i.e a
>>>>>>>>>>> lazy one).
>>>>>>>>>>>
>>>>>>>>>>> Here is a copy, of the generated hibernate mapping where data
>>>>>>>>>>> are collections are well tagged as lazy ones.
>>>>>>>>>>>
>>>>>>>>>>> Help would be appreciated.
>>>>>>>>>>> Stephane.
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> Mapping content :
>>>>>>>>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>>>>>>>> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate
>>>>>>>>>>> Mapping DTD 3.0//EN"
>>>>>>>>>>> "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
>>>>>>>>>>>
>>>>>>>>>>> <hibernate-mapping auto-import="false">
>>>>>>>>>>> <class name="org.eclipse.example.library.impl.BookImpl"
>>>>>>>>>>> entity-name="Book" abstract="false" lazy="true"
>>>>>>>>>>> table="`book`" proxy="org.eclipse.example.library.Book">
>>>>>>>>>>> <meta attribute="eclassName">Book</meta>
>>>>>>>>>>> <meta
>> attribute="epackage">http:///org/eclipse/example/library.ecore</meta>
>>>>>>>>>>>
>>>>>>>>>>> <id type="long" name="e_id" column="e_id"
>>>>>>>>>
>>>>>>>
>>>>
>>
> access=" org.eclipse.emf.teneo.hibernate.mapping.identifier.Identifie rPropertyHandler ">
>
>>>>
>>>>>>>
>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> <meta attribute="syntheticId">true</meta>
>>>>>>>>>>> <generator class="native"/>
>>>>>>>>>>> </id>
>>>>>>>>>>> <version name="e_version" column="e_version"
>>>>>>>>>
>>>>>>>
>>>>
>>
> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHandler ">
>
>>>>
>>>>>>>
>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> <meta attribute="syntheticVersion">true</meta>
>>>>>>>>>>> </version>
>>>>>>>>>>> <property name="title" lazy="false" insert="true"
>>>>>>>>>>> update="true" not-null="false" unique="false"
>>>>>>>>>>> type="java.lang.String">
>>>>>>>>>>> <column not-null="false" unique="false"
>>>>>>>>>>> name="`title`"/>
>>>>>>>>>>> </property>
>>>>>>>>>>> <property name="pages" lazy="false" insert="true"
>>>>>>>>>>> update="true" not-null="false" unique="false" type="int">
>>>>>>>>>>> <column not-null="false" unique="false"
>>>>>>>>>>> name="`pages`"/>
>>>>>>>>>>> </property>
>>>>>>>>>>> <property name="category" lazy="false"
>>>>>>>>>>> not-null="false" insert="true" update="true" unique="false">
>>>>>>>>>>> <column not-null="false" unique="false"
>>>>>>>>>>> name="`category`"/>
>>>>>>>>>>> <type
>>>>>>>>>>> name="org.eclipse.emf.teneo.hibernate.mapping.ENumUserType" >
>>>>>>>>>>> <param
>>>>>>>>>>> name="enumClass">org.eclipse.example.library.BookCategory</param >
>>>>>>>>>>>
>>>>>>>>>>> </type>
>>>>>>>>>>> </property>
>>>>>>>>>>> <many-to-one name="author" entity-name="Writer"
>>>>>>>>>>> lazy="proxy" foreign-key="book_author" insert="true"
>>>>>>>>>>> update="true" not-null="false">
>>>>>>>>>>> <column not-null="false" unique="false"
>>>>>>>>>>> name="`book_author_e_id`"/>
>>>>>>>>>>> </many-to-one>
>>>>>>>>>>> </class>
>>>>>>>>>>> <class
>>>>>>>>>>> name="org.eclipse.example.library.impl.LibraryImpl"
>>>>>>>>>>> entity-name="Library" abstract="false" lazy="true"
>>>>>>>>>>> table="`library`" proxy="org.eclipse.example.library.Library">
>>>>>>>>>>> <meta attribute="eclassName">Library</meta>
>>>>>>>>>>> <meta
>> attribute="epackage">http:///org/eclipse/example/library.ecore</meta>
>>>>>>>>>>>
>>>>>>>>>>> <id type="long" name="e_id" column="e_id"
>>>>>>>>>
>>>>>>>
>>>>
>>
> access=" org.eclipse.emf.teneo.hibernate.mapping.identifier.Identifie rPropertyHandler ">
>
>>>>
>>>>>>>
>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> <meta attribute="syntheticId">true</meta>
>>>>>>>>>>> <generator class="native"/>
>>>>>>>>>>> </id>
>>>>>>>>>>> <version name="e_version" column="e_version"
>>>>>>>>>
>>>>>>>
>>>>
>>
> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHandler ">
>
>>>>
>>>>>>>
>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> <meta attribute="syntheticVersion">true</meta>
>>>>>>>>>>> </version>
>>>>>>>>>>> <property name="name" lazy="false" insert="true"
>>>>>>>>>>> update="true" not-null="false" unique="false"
>>>>>>>>>>> type="java.lang.String">
>>>>>>>>>>> <column not-null="false" unique="false"
>>>>>>>>>>> name="`name`"/>
>>>>>>>>>>> </property>
>>>>>>>>>>> <list name="writers" lazy="true"
>>>>>>>>>>> cascade="all,delete-orphan">
>>>>>>>>>>> <key update="true" foreign-key="library_writers">
>>>>>>>>>>> <column name="`library_writers_e_id`"
>>>>>>>>>>> not-null="false" unique="false"/>
>>>>>>>>>>> </key>
>>>>>>>>>>> <list-index column="`library_writers_idx`"/>
>>>>>>>>>>> <one-to-many entity-name="Writer"/>
>>>>>>>>>>> </list>
>>>>>>>>>>> <list name="books" lazy="true"
>>>>>>>>>>> cascade="all,delete-orphan">
>>>>>>>>>>> <key update="true" foreign-key="library_books">
>>>>>>>>>>> <column name="`library_books_e_id`"
>>>>>>>>>>> not-null="false" unique="false"/>
>>>>>>>>>>> </key>
>>>>>>>>>>> <list-index column="`library_books_idx`"/>
>>>>>>>>>>> <one-to-many entity-name="Book"/>
>>>>>>>>>>> </list>
>>>>>>>>>>> </class>
>>>>>>>>>>> <class name="org.eclipse.example.library.impl.WriterImpl"
>>>>>>>>>>> entity-name="Writer" abstract="false" lazy="true"
>>>>>>>>>>> table="`writer`" proxy="org.eclipse.example.library.Writer">
>>>>>>>>>>> <meta attribute="eclassName">Writer</meta>
>>>>>>>>>>> <meta
>> attribute="epackage">http:///org/eclipse/example/library.ecore</meta>
>>>>>>>>>>>
>>>>>>>>>>> <id type="long" name="e_id" column="e_id"
>>>>>>>>>
>>>>>>>
>>>>
>>
> access=" org.eclipse.emf.teneo.hibernate.mapping.identifier.Identifie rPropertyHandler ">
>
>>>>
>>>>>>>
>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> <meta attribute="syntheticId">true</meta>
>>>>>>>>>>> <generator class="native"/>
>>>>>>>>>>> </id>
>>>>>>>>>>> <version name="e_version" column="e_version"
>>>>>>>>>
>>>>>>>
>>>>
>>
> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHandler ">
>
>>>>
>>>>>>>
>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> <meta attribute="syntheticVersion">true</meta>
>>>>>>>>>>> </version>
>>>>>>>>>>> <property name="name" lazy="false" insert="true"
>>>>>>>>>>> update="true" not-null="false" unique="false"
>>>>>>>>>>> type="java.lang.String">
>>>>>>>>>>> <column not-null="false" unique="false"
>>>>>>>>>>> name="`name`"/>
>>>>>>>>>>> </property>
>>>>>>>>>>> <list name="books" table="`writer_books`" lazy="true">
>>>>>>>>>>> <key update="true">
>>>>>>>>>>> <column name="`writer_e_id`" not-null="true"
>>>>>>>>>>> unique="false"/>
>>>>>>>>>>> </key>
>>>>>>>>>>> <list-index column="`writer_books_idx`"/>
>>>>>>>>>>> <many-to-many entity-name="Book" unique="true">
>>>>>>>>>>> <column name="`book_e_id`" not-null="true"
>>>>>>>>>>> unique="false"/>
>>>>>>>>>>> </many-to-many>
>>>>>>>>>>> </list>
>>>>>>>>>>> </class>
>>>>>>>>>>> </hibernate-mapping>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>
>>>>
>>>>
>>>>
>
>


--

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:Re: Value holding in CDO model
Next Topic:[CDO] Restore Resource from Audit
Goto Forum:
  


Current Time: Thu May 28 05:44:49 GMT 2020

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

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

Back to the top