Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » EclipseLink and MongoDB - Auto incrementing field
EclipseLink and MongoDB - Auto incrementing field [message #1063780] Fri, 14 June 2013 04:21 Go to next message
Michael Hunziker is currently offline Michael Hunziker
Messages: 4
Registered: June 2013
Junior Member
Dear all!

We're using Eclipse Link 2.4 with MongoDB.

Due to a business requirement we need to be able to generate an auto incrementing sequence (as documented here: docs.mongodb.org/manual/tutorial/create-an-auto-incrementing-field)

Has anyone ever had to do this? The problem is that the ObjectID's are not really human readable. E.g. in URLs: htt...://bookStore.com/books/51BAB665040EE9317CAD525A.
Our customer would like to be able to use an ID like 1234 to identify a book...

What do you think about this?
Is there a possibility to implement the solution proposed by MongoDB above with EclipseLink/NOSQL? Currently I don't see how I could call the mongodb-function "getNextSequence"...

Thank you for your help!

Cheers
Michael

Re: EclipseLink and MongoDB - Auto incrementing field [message #1064285 is a reply to message #1063780] Tue, 18 June 2013 10:39 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

You can use a native query to create your id and either assign it to your object yourself, or use a custom Sequence in EclipseLink to use your function to define the id.

Another option would be to map a Sequence entity to a collection and keep a counter field in it that you increment and commit to get a new id (use optimistic locking).


James : Wiki : Book : Blog : Twitter
Re: EclipseLink and MongoDB - Auto incrementing field [message #1064293 is a reply to message #1064285] Tue, 18 June 2013 10:52 Go to previous message
Michael Hunziker is currently offline Michael Hunziker
Messages: 4
Registered: June 2013
Junior Member
Perfect, thank you James!
Previous Topic:SetFirstResult and setMaxResult problem if exist @OneToMany relation
Next Topic:@OneToMany and @ManyToOne in MongoDB and JPA -EISOneToOneMapping cannot be cast to
Goto Forum:
  


Current Time: Fri Apr 18 14:31:41 EDT 2014

Powered by FUDForum. Page generated in 0.08693 seconds