-->
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.  [ 6 posts ] 
Author Message
 Post subject: Generate ObjectId values for _id in Mongo
PostPosted: Mon Mar 24, 2014 1:43 am 
Newbie

Joined: Mon Mar 24, 2014 1:10 am
Posts: 3
How to accoumplish subj?
Nothing about strategies in documentation.
@GeneratedValue(generator = "native") doesn't work.


Top
 Profile  
 
 Post subject: Re: Generate ObjectId values for _id in Mongo
PostPosted: Tue Mar 25, 2014 8:21 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
Hi,
these generation strategies should work:

Code:
@Entity
public class Helicopter {
      ...
@Id
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid2")
   public String getId() {
      return uuid;
   }
...
}


or

Code:
@Entity
public class Helicopter {

...
   @Id
   @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "helicopter_seq")
   @SequenceGenerator(name = "helicopter_seq")
   public Integer getId() {
      return id;
   }
...
}


or

Code:
@Entity
public class Helicopter {

...
   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   public Long getId() {
      return id;
   }
..
}


Top
 Profile  
 
 Post subject: Re: Generate ObjectId values for _id in Mongo
PostPosted: Tue Mar 25, 2014 4:21 pm 
Newbie

Joined: Mon Mar 24, 2014 1:10 am
Posts: 3
They work, but don't do the thing.
Consider ObjectId
Quote:
ObjectId is a 12-byte BSON type, constructed using:

a 4-byte value representing the seconds since the Unix epoch,
a 3-byte machine identifier,
a 2-byte process id, and
a 3-byte counter, starting with a random value.


versus uuid
Quote:
uuid
Generates a 128-bit UUID based on a custom algorithm. The value generated is represented as a string of 32 hexidecimal digits. Users can also configure it to use a separator (config parameter "separator") which separates the hexidecimal digits into 8{sep}8{sep}4{sep}8{sep}4. Note specifically that this is different than the IETF RFC 4122 representation of 8-4-4-4-12.


As for two other options here is another quote from mongodb.org
Quote:
WARNING
Generally in MongoDB, you would not use an auto-increment pattern for the _id field, or any field, because it does not scale for databases with large numbers of documents. Typically the default value ObjectId is more ideal for the _id.


Top
 Profile  
 
 Post subject: Re: Generate ObjectId values for _id in Mongo
PostPosted: Thu Mar 27, 2014 8:19 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
Good point,
at the moment is not possible to use the mongodb generated ObjectId.


Top
 Profile  
 
 Post subject: Re: Generate ObjectId values for _id in Mongo
PostPosted: Fri May 23, 2014 3:02 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
I've created https://hibernate.atlassian.net/browse/OGM-526 to track this requirement. Definitely something we should support some time soon.

--Gunnar

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


Top
 Profile  
 
 Post subject: Re: Generate ObjectId values for _id in Mongo
PostPosted: Wed Oct 01, 2014 5:42 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
Hibernate OGM now supports this feature: http://in.relation.to/Bloggers/MongoDBObjectIdSupportAndRestructuredPublicAPIHibernateOGM410Beta7IsOut


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