-->
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.  [ 7 posts ] 
Author Message
 Post subject: List and inverse="true" (again)
PostPosted: Fri Sep 12, 2003 5:37 am 
Beginner
Beginner

Joined: Fri Sep 12, 2003 5:13 am
Posts: 22
Hello,

I'm sorry to ask again about this topic, but I've some problem to understand the way to use List with inverse="true".

There are many other posts on this (like http://forum.hibernate.org/viewtopic.php?t=330), but I think it could be interesting to have a clarification on this point (and add it to the FAQ).

With a mapping like this :

<list
name="associations"
lazy="true"
inverse="true"
cascade="all">
<key column="key"/>
<index column="idx" />
<one-to-many class="com.foo.Whatever" />
</list>

the index column is not updated to the database. So, what to do :
- map the index column and put manually the collection index into the mapped index field ?
- Use inverse="false" (what are the risks of this ?) ?
- What else

Thanks for the clarification.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2003 5:46 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Either of those work. The second might perform badly.

I absolutely busted my brain trying to figure out a way to implement this w/o the need for an "index property", so that it would work for detached objects, and w/o requiring buildtime bytecode tricks.

But there is no way, AFAIK.


Top
 Profile  
 
 Post subject: Re: List and inverse="true" (again)
PostPosted: Fri Sep 12, 2003 6:33 am 
Beginner
Beginner

Joined: Fri Sep 12, 2003 5:13 am
Posts: 22
Thanks for the quick answer.

[quote="Philippe Chal


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2003 6:38 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Yes its bugprone. Still, if you implement it in a addChild() method, its doable.


I personally do *not* recommend using Lists for a Parent/Child type relationships. They are good for "weaker" relationships where you can use inverse="false".


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2003 7:03 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Note that an *almost* correct implementation of the index() property is:

Code:
public void setIndex(int ind) {
    index = ind;
}
public int getIndex() {
    if ( Hibernate.isInitialized( parent.getChildren() ) ) {
        index = parent.getChildren().indexOf(this);
    }
    return index;
}



Though this does break when Parent is mapped with a proxy.

And that really is where all my problems with detached objects start. :(

I don't want to implement anything where we have to go back to the database to retrieve the value of the index column when I update() a Child with an uninitialized Parent.

And I don't want to give up Hibernate's model of startup-time SQL generation.

So I'm kinda stuck :(


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 01, 2003 11:07 pm 
Beginner
Beginner

Joined: Wed Oct 01, 2003 11:01 pm
Posts: 23
gavin wrote:
Note that an *almost* correct implementation of the index() property is:

Code:
public void setIndex(int ind) {
    index = ind;
}
public int getIndex() {
    if ( Hibernate.isInitialized( parent.getChildren() ) ) {
        index = parent.getChildren().indexOf(this);
    }
    return index;
}



Though this does break when Parent is mapped with a proxy.


Gavin, I just want to make sure I'm reading this correctly: the code is correct as long as parent is NOT mapped with a proxy, correct?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 02, 2003 4:40 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
yeah, I think so.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.