[hibernate-dev] [OGM] Keeping the order of the collection of elements in MongoDB
Davide D'Alto
davide at hibernate.org
Fri Jan 13 10:30:16 EST 2017
I've created a JIRA for this https://hibernate.atlassian.net/browse/OGM-1236
Thanks
On Fri, Jan 13, 2017 at 2:26 PM, Sanne Grinovero <sanne at hibernate.org> wrote:
> Hi Yoann,
>
> while you might be using a specific implementation when persisting
> your new entities, when you're loading the object back from the
> database how is Hibernate supposed to know
> A) which implementation you want it to use
> B) which order to use, if you didn't map e.g. an order column to
> store the ordering information (MongoDB not needing a strategy is an
> exception)
>
> The entity model expresses the intent of the end user, but also it
> expresses its requirements which will be taken into account by ORM
> when it needs to provide an implementation for the "Collection"
> interface.
>
> A List expresses the ordering requirement by contract; if you map a
> relation as "Collection" I wage you're not interested in the order,
> but you're rather more interested in accepting a wide range of
> implementations, some of which might ignore the ordering requirement.
> By doing so, you're explicitly telling both ORM and your other code
> interacting with the model that ignoring the order is acceptable.
>
> BTW I suspect mapping things as a generic Collection is a very unusual
> (or lazy) choice; I don't remember ever using it as it's quite
> ambiguous, and there's no way any specification diagram will lead you
> to recommend using a Collection (other than cleanly and explicitly
> wanting to express you don't care about ordering, nor other properties
> like uniqueness...)
>
> Thanks,
> Sanne
>
>
> On 13 January 2017 at 13:29, Yoann Rodiere <yrodiere at redhat.com> wrote:
>>> I think it's a reasonable expectation, as long as we're talking
>>> specifically about mapping a *List* and not just a generic Collection.
>>
>>
>> Ah, this topic again :) I know I'll be all lone, but I'll try anyway!
>>
>> If we do it for List, and unless there are technical issues that prevent us
>> from doing so, I would be in favor of doing it for any kind of collection.
>>
>> In Collections, the fact that iteration order is deterministic is mostly up
>> to the implementation, which is different from saying it's not
>> deterministic. From the javadoc for Collection#iterator():
>>
>>> There are no guarantees concerning the order in which the elements are
>>> returned
>>> (unless this collection is an instance of some class that provides a
>>> guarantee).
>>
>>
>> Deterministic, and even predictable order is not exclusive to List, either:
>> for instance, LinkedHashSet is not a List, it has a specific iteration
>> order, but there is nothing in its implemented interfaces (Collection, Set)
>> that defines this order.
>>
>> My point is, we can't rely on the implemented interface to decide whether
>> the iteration order is important or not, so we may as well decide it is
>> always important. Unless there are annoying technical challenges, of course.
>>
>> Yoann Rodière <yrodiere at redhat.com>
>> Software Engineer
>> Red Hat / Hibernate NoORM Team
>>
>> On 13 January 2017 at 13:48, Sanne Grinovero <sanne at hibernate.org> wrote:
>>>
>>> I think it's a reasonable expectation, as long as we're talking
>>> specifically about mapping a *List* and not just a generic Collection.
>>>
>>> On 13 January 2017 at 12:18, Davide D'Alto <davide at hibernate.org> wrote:
>>> > Hi,
>>> > it seems that when using Collection of elements in MongoDB, users
>>> > expect to have the elements in the same order as in the db. You can
>>> > see the question on the forum here:
>>> >
>>> > https://forum.hibernate.org/viewtopic.php?f=31&t=1043903&p=2491218#p2491218
>>> >
>>> > I also found this StackOverflow question:
>>> >
>>> > http://stackoverflow.com/questions/9013916/do-arrays-stored-in-mongodb-keep-their-order
>>> >
>>> > What do you think? Is it something that we should support?
>>> >
>>> > Cheers,
>>> > Davide
>>> > _______________________________________________
>>> > hibernate-dev mailing list
>>> > hibernate-dev at lists.jboss.org
>>> > https://lists.jboss.org/mailman/listinfo/hibernate-dev
>>> _______________________________________________
>>> hibernate-dev mailing list
>>> hibernate-dev at lists.jboss.org
>>> https://lists.jboss.org/mailman/listinfo/hibernate-dev
>>
>>
More information about the hibernate-dev
mailing list