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.  [ 3 posts ] 
Author Message
 Post subject: Automatic <index>
PostPosted: Wed Jan 03, 2007 8:39 pm 
Newbie

Joined: Wed Jan 03, 2007 8:31 pm
Posts: 2
The fact that an index column needs to be specified for an array is annoying. Most of the time I do not have an index column available. The closest thing is perhaps a sort key column, but there is no guarantee that it is sequential or that it is 0-based.

Wouldn't it make sense to allow nHibernate to generate the index automatically? I understand that arrays are sorted collections, and that the order matters, but why does the order have to be dictated by the index? It seems to me like it would make much more sense to have something like a <sort> node instead of the <index> node. This way I can specifiy the sort order of the array elements without being constrained by sequential values.

Another option would be to simply load the array elements in the order in which they are stored in the table if no <index> column is specified.

Am I missing something, is this or an alternative perhaps already implemented in nHibernate?


Top
 Profile  
 
 Post subject: Re: Automatic <index>
PostPosted: Thu Jan 04, 2007 2:38 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
redlike wrote:
The fact that an index column needs to be specified for an array is annoying. Most of the time I do not have an index column available. The closest thing is perhaps a sort key column, but there is no guarantee that it is sequential or that it is 0-based.

Wouldn't it make sense to allow nHibernate to generate the index automatically? I understand that arrays are sorted collections, and that the order matters, but why does the order have to be dictated by the index? It seems to me like it would make much more sense to have something like a <sort> node instead of the <index> node. This way I can specifiy the sort order of the array elements without being constrained by sequential values.

Another option would be to simply load the array elements in the order in which they are stored in the table if no <index> column is specified.

Am I missing something, is this or an alternative perhaps already implemented in nHibernate?


Have You tried <bag> inestad of <list>?

Gert

_________________
If a reply helps You, rate it!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 04, 2007 10:20 am 
Newbie

Joined: Wed Jan 03, 2007 8:31 pm
Posts: 2
I am not using <list>, I am using <array>:

Code:
<array name="Items" table="OrderItems">
   <key column="intOrderID"/>
   <index column="intSortKey"/>
   <one-to-many class="OrderItem"/>
</array>


All the solutions I was able to find suggest changing the object model, so that instead of an array I use some kind of IList or other collection class.

I need to use an array so that I have a strongly typed collection of items. It seems silly that I would need to change my object model to accomodate Hibernate. It should be the other way around, Hibernate should be able to accomodate any reasonable object model.

What seems natural to me would be something like:

Code:
<array name="Items" table="OrderItems">
   <key column="intOrderID"/>
   <sort column="intSortKey"/>
   <one-to-many class="OrderItem"/>
</array>


Is there another way to achieve this in Hibernate?


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