-->
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:
PostPosted: Sat Apr 03, 2004 8:45 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
You could, I suppose, keep track of an "appended list"


That is exactly what Hibernate does.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 03, 2004 8:49 pm 
Newbie

Joined: Sat Apr 03, 2004 11:40 am
Posts: 17
gavin wrote:
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


Lists can be inverse? Where do they pick up the index?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 03, 2004 9:04 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
You would define an index property on the child class and set its value manually. This would not work for a many-to-many association, or course. You would need to use a composite-element mapping instead of a many-to-many.

Alternatively, you could use a bag with an order-by to achieve much the same effect.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 03, 2004 9:06 pm 
Newbie

Joined: Sat Apr 03, 2004 11:40 am
Posts: 17
Aha, I get it. So, then:
Code:
..
        <list name="lines" inverse="true" lazy="true">
            <key column="parent"/>
            <index column="lineNumber" type="integer"/>
            <one-to-many class="eg.Line"/>
        </list>
...
    <class name="eg.Line" table="lines">
        <id name="id" type="long">
            <generator class="hilo"/>
        </id>
        <property name="line" type="text"/>
    </class>


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 03, 2004 9:09 pm 
Newbie

Joined: Sat Apr 03, 2004 11:40 am
Posts: 17
Hmm, did I get that wrong then? It seems to build a sensible schema, puts the index and parent fields into the lines table. Lacking an index key in the <class> it could only be insertable via the list... or would it just break?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 03, 2004 10:04 pm 
Beginner
Beginner

Joined: Fri Apr 02, 2004 3:34 am
Posts: 40
gavin wrote:
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.


It think it is probably worthwhile to include a special Hibernate Persistent Collections that do not necessarily adhere to the Java Collectoins API.


Top
 Profile  
 
 Post subject: A Question Or Two
PostPosted: Sat Apr 03, 2004 10:10 pm 
Beginner
Beginner

Joined: Fri Apr 02, 2004 3:34 am
Posts: 40
Organzation --*> Employee

Employee list is a lazy list.

When I use a session to load Organization, the Employee list won't load the Employees unless I "touch" it, right?

Does Hibenate load Employee proxies still? That would be bad for me because I may have literally millions of Employees.

I would like the Employee list to remain EMPTY with no elements whatsover in it until I touch it. Is that possible?

Now, I close the session and send the Organization further up the system to the UI, where a new Employee is added to the same Organization object instance. The Employee list should now contain exactly 1 element right? And so, I can proceed to send Organization down again and then persist the new Employee ???

Thanks...!
Acco


Top
 Profile  
 
 Post subject: Hibernate Persistent Collection
PostPosted: Sat Apr 03, 2004 10:18 pm 
Beginner
Beginner

Joined: Fri Apr 02, 2004 3:34 am
Posts: 40
Acco Lade wrote:
gavin wrote:
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.


It think it is probably worthwhile to include a special Hibernate Persistent Collections that do not necessarily adhere to the Java Collectoins API.


Suggestion on a Hibernate/ Persistent Collection (HPC) semantics:

HPC = aka High Performance Collection :-)

1. Consider the HPC to be a filtered view of the persistent data. That is, it includes only chosen elements.
2. Include an option where one can pass "init" and pass in the filter/query for the Collection.

Many time, we hold a ref to an Organization, but we are not interested in all Employees, and hence, it would be nice to be able to retrieve Employee via Organization and a filter.

At the time the changes are committed to the database, if the Employee instances currently in the HPC conflict with what is in the datastore, simply throw an exception.

In other words, don't load all the data into memory, let the database worry about duplicate rows, bad foreign keys, and such at commit time.

What says?
Acco


Top
 Profile  
 
 Post subject: Re: Hibernate Persistent Collection
PostPosted: Sat Apr 03, 2004 10:21 pm 
Beginner
Beginner

Joined: Fri Apr 02, 2004 3:34 am
Posts: 40
Acco Lade wrote:
In other words, don't load all the data into memory, let the database worry about duplicate rows, bad foreign keys, and such at commit time.

What says?
Acco


I mean, don't even instantiate the proxies. The HPC should be empty -- no elements in it at all.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 03, 2004 10:29 pm 
Beginner
Beginner

Joined: Fri Apr 02, 2004 3:34 am
Posts: 40
I don't disagree with you with regard to the Java Collections API semantics, but I think they should apply to in-memory object instances, what's been directed to be loaded. I see no need to drag the datatstore into memory or the proxies for that matter, unless someone asked for them.

If there is a conflict with the datastore, let the datastore handle it at commit time. We've all seen and know how to handle the PK and FK constraint exceptions. That's no big deal!

We probably need to introduce another set of Persistent Collections --
please see other posts.

Acco


brenuart wrote:
Acco Lade wrote:
Que? You mean if I have a Organization with a List of Employee, I cannot add a new Employee without loading the entire Employee table?


That's true. Hibernate will need to load the entire collection before adding the new element. Why so? Because it needs to enforce the Java collection semantic. Think about it...

- The collection is a set: duplicates must be avoided - so when adding a new element, Hibernate needs to know all the others (at least their ID).

- The collection is a map: keys need to be known for the map to be usable...

- The collection is a list: the indices must be known...

- The only collection that *may* not require to know anything in advance is the bag (and I'm not even sure about it) - but this is not a regular java collection type...

Acco Lade wrote:
So, all the one-to-many relationships are esenstially useless unless we are talking about a very small -many instanstances?


Useless? Why so? It will perform correctly in all cases - but with bad performance with very large collections - unless you know what you are doing and use the tool accordingly.


Acco Lade wrote:
I guess the work-around is to add the Employee separately?


The easiest workaround in this case is probably to define the list element as lazy. This way Hibernate won't load their actual content but just a proxy with their IDs... This is quite efficient, believe me ;)

Think about it... Loading the element IDs will be required anyway - whatever is your strategy to update the list, you will at least need this information...


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 04, 2004 2:03 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
>> When I use a session to load Organization, the Employee list won't load the Employees unless I "touch" it, right?


Of course.

Quote:
>> Does Hibenate load Employee proxies still? That would be bad for me because I may have literally millions of Employees.


Depends upon whether it is a one-to-many or a many-to-many. Obviously, for a one-to-many, the behavior you suggest would be absurdly inefficient. For a many-to-many it is the default behavior, which can be overridden by setting outer-join="true" on the <many-to-many> element.


Quote:
>> I would like the Employee list to remain EMPTY with no elements whatsover in it until I touch it. Is that possible?


Ummm. Of course.

Quote:
>> Now, I close the session and send the Organization further up the system to the UI, where a new Employee is added to the same Organization object instance. The Employee list should now contain exactly 1 element right? And so, I can proceed to send Organization down again and then persist the new Employee ??? <<


Negative, this behavior is not supported. The add-w/o-initialize functionalityt is only possible for a collection that is currently connected to an open session. This is a Very Good Thing. Your suggestion would be incredibly evil, since some operations of some collections would be available for uninitialized collections but most would not. I am not going to try and support that kind of confusing, inconsistent functionality!


Quote:
>>It think it is probably worthwhile to include a special Hibernate Persistent Collections that do not necessarily adhere to the Java Collectoins API.<<<


Negative. That is contrary to the entire philosophy of the project.


If you want non-transparent-persistence, you can incredibly easily use queries instead of collections. Indeed, it is never necessary to use collections anywhere in the domain model. They are always "sugar".[/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 04, 2004 3:27 am 
Beginner
Beginner

Joined: Fri Apr 02, 2004 3:34 am
Posts: 40
Well, in short, I need to add a new Employee to an existing Organization with millions of existing Employees, what's the cleanest way? What do you recommend?

Organizaton has a one-to-many relationship with Employee.

Thanks,
Acco


Quote:
>> I would like the Employee list to remain EMPTY with no elements whatsover in it until I touch it. Is that possible?


Ummm. Of course.

Quote:
>> Now, I close the session and send the Organization further up the system to the UI, where a new Employee is added to the same Organization object instance. The Employee list should now contain exactly 1 element right? And so, I can proceed to send Organization down again and then persist the new Employee ??? <<


Negative, this behavior is not supported. The add-w/o-initialize functionalityt is only possible for a collection that is currently connected to an open session. This is a Very Good Thing. Your suggestion would be incredibly evil, since some operations of some collections would be available for uninitialized collections but most would not. I am not going to try and support that kind of confusing, inconsistent functionality!


Quote:
>>It think it is probably worthwhile to include a special Hibernate Persistent Collections that do not necessarily adhere to the Java Collectoins API.<<<


Negative. That is contrary to the entire philosophy of the project.


If you want non-transparent-persistence, you can incredibly easily use queries instead of collections. Indeed, it is never necessary to use collections anywhere in the domain model. They are always "sugar".[/quote][/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 04, 2004 3:45 am 
Beginner
Beginner

Joined: Fri Apr 02, 2004 3:34 am
Posts: 40
I tend to work bottom-up. That is, the database is the domain model and I consider the POJO hiearachy to be "views" into the database at a given time.

So, it would be incredibly convenient to pull out a POJO "view" including make modifications and stuff everything back. That would mean pull out an Organization with certain org criteria along with a Set of Employees that match certain employee criterias, work on that POJO and then stuff everything back.

I only need to pass around a single reference to Organization and I can add to it, modify its structure, etc. That's convenient, but that does not seem possible with the current and future Hibernate plans?

Now, I see that you consider a Set and elements in a Set to be both the in-memory and the datastore. I think there is no need to ensure that an element in a Set is unique across the run-time in-memory space and the datastore.


gavin wrote:
Quote:
>> When I use a session to load Organization, the Employee list won't load the Employees unless I "touch" it, right?


Of course.

Quote:
>> Does Hibenate load Employee proxies still? That would be bad for me because I may have literally millions of Employees.


Depends upon whether it is a one-to-many or a many-to-many. Obviously, for a one-to-many, the behavior you suggest would be absurdly inefficient. For a many-to-many it is the default behavior, which can be overridden by setting outer-join="true" on the <many-to-many> element.


Quote:
>> I would like the Employee list to remain EMPTY with no elements whatsover in it until I touch it. Is that possible?


Ummm. Of course.

Quote:
>> Now, I close the session and send the Organization further up the system to the UI, where a new Employee is added to the same Organization object instance. The Employee list should now contain exactly 1 element right? And so, I can proceed to send Organization down again and then persist the new Employee ??? <<


Negative, this behavior is not supported. The add-w/o-initialize functionalityt is only possible for a collection that is currently connected to an open session. This is a Very Good Thing. Your suggestion would be incredibly evil, since some operations of some collections would be available for uninitialized collections but most would not. I am not going to try and support that kind of confusing, inconsistent functionality!


Quote:
>>It think it is probably worthwhile to include a special Hibernate Persistent Collections that do not necessarily adhere to the Java Collectoins API.<<<


Negative. That is contrary to the entire philosophy of the project.


If you want non-transparent-persistence, you can incredibly easily use queries instead of collections. Indeed, it is never necessary to use collections anywhere in the domain model. They are always "sugar".
[/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 04, 2004 5:13 am 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
gavin wrote:
(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.


Ok, that's the conclusion we came to as well - thanks for the clarification Gavin.

But, I though it is not possible to have inverse indexed collections (how would it be possible anyway) ... So what about your point (1) above ?

Another issue was to know if Hibernate would load the collection member if these entities are marked as "lazy" - or if it would only instantiate proxies for them ?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 04, 2004 5:15 am 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
Sorry about my previous post - didn't notice there was a third page :(
Please consider it as null - the thread already contains the answers I'm looking for.


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.