-->
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: Embedded collection
PostPosted: Thu Jan 12, 2017 12:25 am 
Newbie

Joined: Thu Jan 12, 2017 12:03 am
Posts: 4
Hi everyone,

When I persist object with embedded collection that is defined like

Code:

   ...
   private List<TimeInstant> values;

   @ElementCollection
   @Column(name = "values")
   public List<TimeInstant> getValues() {
      return values;
   }

   ....


this collection got persisted in random order.
I mean if my list is
Code:
{timeInstant1, timeInstant2, timeInstant3}

in database it may look like
Code:
"values" : [
        { timeInstant2 }, { timeInstant1 }, { timeInstant3 }
]


List is initiated as an ArrayList.
Database is MongoDB
Hibernate version is 5.1.0.Beta3

Is there a way I can get the same order in a database as it is in a list?
Ordering after fetching data is not an option for me.

Thanks.


Top
 Profile  
 
 Post subject: Re: Embedded collection
PostPosted: Thu Jan 12, 2017 9:07 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
You can use the annotation @OrderColumn:

Code:
   @ElementCollection
   @OrderColumn(name = "instantIndex")
   private List<TimeInstant> values;


It will change the mapping on the db thougfh, it will look something like:

Code:
        "values" : [
                {
                        "instantIndex" : 0,
                        "timeistant" : "instant1"
                },
                {
                        "instantIndex" : 2,
                        "timeistant" : "instant3"
                },
                {
                        "instantIndex" : 1,
                        "timeistant" : "instant2"
                }
        ]


Does it help?


Top
 Profile  
 
 Post subject: Re: Embedded collection
PostPosted: Thu Jan 12, 2017 3:49 pm 
Newbie

Joined: Thu Jan 12, 2017 12:03 am
Posts: 4
Thanks for your answer.

Unfortunately It will not help - other projects use the same DB and they expect exact order. In particular Scala libraries write collections with respect to original order.

So I was wondering is there a way to achieve it with Hibernare?


Top
 Profile  
 
 Post subject: Re: Embedded collection
PostPosted: Fri Jan 13, 2017 6:44 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
I don't think there is a way a the moment but I'll have a look.

Thanks for the feedback, by the way.

Out of curiosity, what Scala library are you using?


Top
 Profile  
 
 Post subject: Re: Embedded collection
PostPosted: Fri Jan 13, 2017 11:55 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
I've created an issue to keep track of this: https://hibernate.atlassian.net/browse/OGM-1236


Top
 Profile  
 
 Post subject: Re: Embedded collection
PostPosted: Sun Jan 15, 2017 9:11 pm 
Newbie

Joined: Thu Jan 12, 2017 12:03 am
Posts: 4
on scala side we use casbah and salat

I would really appreciate if you could reflect subject issue in hibernate docs explicitly so other folks could avoid this trap entirely or make adjustments at early stage.

Anyway, many thanks for doing this amazing job. It was a please to work with it even if at the end it didn't fit me.


Top
 Profile  
 
 Post subject: Re: Embedded collection
PostPosted: Mon Jan 16, 2017 6:55 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
That's a good suggestion,

Please, let us know if there are some other places where we can improve.

Thanks,
Davide


Top
 Profile  
 
 Post subject: Re: Embedded collection
PostPosted: Tue Oct 31, 2017 6:59 pm 
Newbie

Joined: Thu Jan 12, 2017 12:03 am
Posts: 4
Hi guys,

I see that the tickets are closed now, but I didn't get what way did you choose respect an order or add a note to the documentation?
I had a look at tickets, all docs attached to the tickets, Hibernate OGM docs - and found nothing. sorry if I was blind =)


Top
 Profile  
 
 Post subject: Re: Embedded collection
PostPosted: Wed Nov 01, 2017 6:01 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
It will respect the order.

Cheers


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.