-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 47 posts ]  Go to page Previous  1, 2, 3, 4  Next
Author Message
 Post subject: Re: Not necessary
PostPosted: Sat Apr 03, 2004 5:43 pm 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
JulianMorrison wrote:
You could, I suppose, keep track of an "appended list": if nothing else but add() has touched the list, then you can keep an in-memory in-sequence list of items appended, and batch-append them at flush time (or batch-append at list-initialization time if something else touches the list).

Appending to huge lists is not a marginal case.


I agree with you - but you should then wait for Gavin to reply and possibly tell you why it is not working this way in Hibernate...

I faced the same problem as you and had a look at Hibernate's collection management code... Unfortunately, I couldn't find an easy way to add this kind of behavior :(

So I revert to the lazy elements (with proxies)


Top
 Profile  
 
 Post subject: Re: Lazy list elements
PostPosted: Sat Apr 03, 2004 5:49 pm 
Newbie

Joined: Sat Apr 03, 2004 11:40 am
Posts: 17
JulianMorrison wrote:
So, I'll probably go with the lazy list elements for my case. How do I do this?

Specifically I need to convert
Code:
...
        <list name="lines" table="lines" lazy="true">
            <key column="parent"/>
            <index column="lineNumber" type="integer"/>
            <element column="line" type="text"/>
        </list>
...

so that it uses lazy elements.


Top
 Profile  
 
 Post subject: Re: Lazy list elements
PostPosted: Sat Apr 03, 2004 5:55 pm 
Senior
Senior

Joined: Wed Mar 24, 2004 11:40 am
Posts: 146
Location: Indianapolis, IN, USA
JulianMorrison wrote:
So, I'll probably go with the lazy list elements for my case. How do I do this?


If you are using a list, set or bag, all you have to do is enable lazy by having lazy="true"


Top
 Profile  
 
 Post subject: Re: Lazy list elements
PostPosted: Sat Apr 03, 2004 5:57 pm 
Newbie

Joined: Sat Apr 03, 2004 11:40 am
Posts: 17
gpani wrote:
If you are using a list, set or bag, all you have to do is enable lazy by having lazy="true"

Surely that just sets the list as a whole to lazy? Ie: if nothing touches the list it's not loaded; if anything touches it, it's loaded all at once. That loading-all-at-once is what i'm trying to avoid.


Top
 Profile  
 
 Post subject: Re: Lazy list elements
PostPosted: Sat Apr 03, 2004 6:00 pm 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
JulianMorrison wrote:
JulianMorrison wrote:
So, I'll probably go with the lazy list elements for my case. How do I do this?

Specifically I need to convert
Code:
...
        <list name="lines" table="lines" lazy="true">
            <key column="parent"/>
            <index column="lineNumber" type="integer"/>
            <element column="line" type="text"/>
        </list>
...

so that it uses lazy elements.


Not exactly. This would make the collection lazy - meaning it is not loaded when its owning entity is loaded. It will be the first time you access it.
What you need is to make the elements of the list lazy... But unfortunately, it appears your list content is not persistent entities, but primitive types (strings) :(
If they were persistent entities (with an id) - the could have declared them lazy by adding the 'lazy=true' tag in its mapping definition:

Code:
<class "blabla" lazy="true" >
...
</class>


Top
 Profile  
 
 Post subject: Re: Lazy list elements
PostPosted: Sat Apr 03, 2004 6:04 pm 
Newbie

Joined: Sat Apr 03, 2004 11:40 am
Posts: 17
brenuart wrote:
What you need is to make the elements of the list lazy... But unfortunately, it appears your list content is not persistent entities, but primitive types (strings) :(
If they were persistent entities (with an id) - the could have declared them lazy by adding the 'lazy=true' tag in its mapping definition

So I should wrap the lines in a <class>?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 03, 2004 6:07 pm 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
Small remark to clarify what we said so far:
If I understand the Hibernate code correctly, adding to a collection will not trigger its initialization if:
- the collection is not already loaded;
- the collection is connected to a session;
- and the collection is an inverse collection.

Therefore, it does not apply to indexed collections like lists and maps (which cannot be inverse).

So when you expect a huge collection, and you often append to it - a possible approach would be to make it an inverse collection ?


Top
 Profile  
 
 Post subject: Re: Lazy list elements
PostPosted: Sat Apr 03, 2004 6:09 pm 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
JulianMorrison wrote:
brenuart wrote:
What you need is to make the elements of the list lazy... But unfortunately, it appears your list content is not persistent entities, but primitive types (strings) :(
If they were persistent entities (with an id) - the could have declared them lazy by adding the 'lazy=true' tag in its mapping definition

So I should wrap the lines in a <class>?


I think so...

But before going any further, maybe you should wait a bit for other people to join the thread. Would be nice if we could have opinions of some Hibernate members...

Maybe there is another approach, maybe we are completly wrong... ;)


Top
 Profile  
 
 Post subject: Inverse
PostPosted: Sat Apr 03, 2004 6:13 pm 
Newbie

Joined: Sat Apr 03, 2004 11:40 am
Posts: 17
Lines have sequence, so an inverse <bag> isn't up to the job. I could add <property name="lineNumber" type="long"/> but then I'd have to implement list semantics myself with locking, session.filter(), and so forth.

A list of lazy <class> might work better.


Top
 Profile  
 
 Post subject: Hackishness
PostPosted: Sat Apr 03, 2004 6:19 pm 
Newbie

Joined: Sat Apr 03, 2004 11:40 am
Posts: 17
In fact, if I combine my earlier unique-key hackish manual list with an inverse set, I get list semantics for free! (Well nearly. Technically I get sparse list semantics, and I have to futz with locking to avoid a race on indexes.)


Top
 Profile  
 
 Post subject: Recap
PostPosted: Sat Apr 03, 2004 6:37 pm 
Newbie

Joined: Sat Apr 03, 2004 11:40 am
Posts: 17
A recap, my current state-of-the-art:
Code:
...
        <list name="lines" table="line_ids" lazy="true">
            <key column="stored_email"/>
            <index column="lineNumber" type="integer"/>
            <one-to-many class="eg.Line"/>
        </list>
...
   
    <class name="eg.Line" table="lines" lazy="true">
        <id name="id" type="long">
            <generator class="hilo"/>
        </id>
        <property name="line" type="text"/>
    </class>

Hibernate's schema generator seems actually smart enough to not even need to generate the "line_ids" table.


Top
 Profile  
 
 Post subject: Re: Recap
PostPosted: Sat Apr 03, 2004 6:43 pm 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
JulianMorrison wrote:
A recap, my current state-of-the-art:
...
Hibernate's schema generator seems actually smart enough to not even need to generate the "line_ids" table.


I'm a bit tired (1AM here) but it looks ok.
The "line_ids" is not needed since the foreign key will be stored in the "lines" table...


Top
 Profile  
 
 Post subject: Re: Recap
PostPosted: Sat Apr 03, 2004 6:50 pm 
Newbie

Joined: Sat Apr 03, 2004 11:40 am
Posts: 17
brenuart wrote:
The "line_ids" is not needed since the foreign key will be stored in the "lines" table...

Yeah, the mapping to fields is arcane... I never try to second-guess it, I just have an ant script call the schema export.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 03, 2004 7:01 pm 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
Well, listen - I'm sorry but I made a test and Hibernate is still loading the entire collection and all its elements. Apparently, the lazy class tag doesn't seem to apply to entities when they are in collection...

Very strange, and I can't believe it... It is probably too late and I should better go in my bed... things will become obvious tomorrow :(


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 03, 2004 8:44 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
OK, just a note, there is a lot of incorrect stuff written in this thread. :(

The actual functionality is this:

(1) For bags and lists with inverse="true", add() does not initialize the collection
(2) For all other collection mappings add() does immediately initailize the collection

As noted, this behavior is required in order to comply with the contracts defined by the Java Collections API.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 47 posts ]  Go to page Previous  1, 2, 3, 4  Next

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.