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.  [ 9 posts ] 
Author Message
 Post subject: Manipulating lists and index problem!
PostPosted: Thu Oct 23, 2003 11:49 am 
Newbie

Joined: Thu Oct 23, 2003 10:55 am
Posts: 11
Hi all,

It seems that I misundertood how the transparent persistent collection (managed by reachability) worked with Hibernate.
Here is a sample configuration hbm file with a bidirectionnal Parent-Child relationship:
Code:
<class name="com.oalia.apps.purchaser.bo.common.nomenclature.NomenclatureItem" table="NOMENCLATURE_ITEM"
        dynamic-update="false"
        dynamic-insert="false"
        discriminator-value="1">

        <id name="id" column="ID" type="java.lang.Long" unsaved-value="null">
            <generator class="native"/>
        </id>
        <property
            name="name"
            type="java.lang.String"
            update="true"
            insert="true"
            column="NAME"
            not-null="false"
            unique="false"
        />

        <property
            name="rank"
            type="java.lang.Integer"
            update="true"
            insert="true"
            column="RANK"
            not-null="false"
            unique="false"
        />

        <many-to-one
            name="nomenclature"
            class="com.oalia.apps.purchaser.bo.common.nomenclature.Nomenclature"
            cascade="none"
            outer-join="auto"
            update="false"
            insert="false"
            column="NOMENCLATURE_ID"
            not-null="true"
        />

    </class>
    <class name="com.oalia.apps.purchaser.bo.common.nomenclature.Nomenclature"
        table="NOMENCLATURE"
        dynamic-update="false"
        dynamic-insert="false">

        <id name="id" column="ID" type="java.lang.Integer" unsaved-value="null">
            <generator class="native"/>
        </id>

        <list name="items" lazy="false" inverse="true" cascade="all">
              <key column="NOMENCLATURE_ID"/>
              <index column="RANK"/>
              <one-to-many class="com.oalia.apps.purchaser.bo.common.nomenclature.NomenclatureItem"/>
        </list>
        <property
            name="name"
            type="java.lang.String"
            update="true"
            insert="true"
            column="NAME"
            not-null="false"
            unique="false"/>
    </class>


The main problem is that index column and the represented child field (rank) are not updated. That means that:
Code:
nomenclature.getItems().add(new NomenclatureItem("n1"));
nomenclature.getItems().add(new NomenclatureItem("n2"));

the ranks are not set, and when retrieving the items in another session, the objects will not have the correct index.
The other problem is that the collection is not as persistent as it seams.
For instance:
Code:
Transaction tx = session.beginTransaction();
Nomenclature nomenclature = ... // Gets the nomenclature
NomenclatureItem ni = (NomenclatureItem)nomenclature.remove(3);
// The size of the items is n-1 in memory
tx.commit();
...
nomenclature = ... // Gets the same nomenclature
System.out.println(nomenclature.getItems().size()); // will display n !!!


Is there a mistake in the above code or is it a normal feature of the persistent indexed List?

Thanks in advance.

MG


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2003 12:33 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
1. as you said by the inverse="true", nomenclature item is responsible for link.
So nomenclatureItem.setNomenclature(nomenclature) is mandatory

2. lists can contains null objects and start from index 0, not 1.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2003 12:53 pm 
Newbie

Joined: Thu Oct 23, 2003 10:55 am
Posts: 11
Sorry I would say:
Code:
nomenclature.addItem(new NomenclatureItem("n1"));
nomenclature.addItem(new NomenclatureItem("n2"));

when addItem will do the two operation (setNomenclature and getItems().add()).

does anybody know a solution to automatically manage the item index (as a persistent list does...).

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2003 1:13 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Code:
<many-to-one
            name="nomenclature"
            class="com.oalia.apps.purchaser.bo.common.nomenclature.Nomenclature"
            cascade="none"
            outer-join="auto"
            update="true"
            insert="true"
            column="NOMENCLATURE_ID"
            not-null="true"
        />


update=true, insert=true.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2003 1:48 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
does anybody know a solution to automatically manage the item index (as a persistent list does...).


No, it is virtually impossible to implement since Hibernate objects are not assumed to be always under the management of the container, and since we prefer to generate SQL at startup. We have discussed the difficulties with this many times before.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 24, 2003 3:08 am 
Newbie

Joined: Thu Oct 23, 2003 10:55 am
Posts: 11
Thanks a lot,

So to conclude, lets imagine that we have a persistent list managed with the index property like:
Code:
l = [o1, o2, o3, o4]

If in a transaction we are doing:
Code:
tx = session.gebeginTransaction();
l.remove(1); // here the list is [o1, o3, o4]
tx.commit()

When the next time we will retrieve the list it, will be
Code:
[o1, null, o3, o4]

That is different from before the commit...

Is that right?
So the list can not be considered as a Persistent List (as the JDO/ODMG specified)?

Thanks again

MG


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 24, 2003 5:05 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Ummm Hibernate is not ODMG/JDO - it is much more powerful. (Hibernate supports detached instances, which is the reason for the difference).

And anyway if you use inverse="false" you will get the behaviour you just described.

Now, your snide tone is not appreciated and believe me I have spent much, much more time thinking about this problem than you, or anyone on the JDO or ODMG expert groups.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 26, 2003 2:32 pm 
Newbie

Joined: Thu Oct 23, 2003 10:55 am
Posts: 11
Sorry about the tone,

* First of all I really appreciate the time you spend on answering my question (and as anyone on Hibernate - that is an extraordinary Persistent OR Binding Tool) .

* Believe me I did not try to be aggressive, I just wanted to understand how the things work. Please excuse me but my english is not as good as my french to explain this kind of things. I did not want to give a particular tone to my message (and not arrogant at all).

* I image you spend a lot of time thinking about this difficult problem. Let me say that I spend a lot of time too - I activelly participated in one of the first OR binding implementing ODMG in the first release, developped in Java for a customer called Sun (when I worked for O2 Tech.). I know this problem is difficult (as some others that are remarkably treated in Hibernate). I was just trying to understand the difference with the DList specification that are implemented by the Hibernate Persistent List and that are explicitly featured that point. You gave me the solution (inverse="false") and thanks a lot.

Sorry again and Thanks Gavin.

I hope we will have other discussions and I tried to spend time to make my messages kinder.

Mathieu


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 26, 2003 4:27 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
No problem :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 

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.