Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » NoSQL|Mongo : How to use ObjectID ?
NoSQL|Mongo : How to use ObjectID ? [message #1411128] Fri, 22 August 2014 13:10 Go to next message
Tugdual Grall is currently offline Tugdual GrallFriend
Messages: 1
Registered: July 2009
Junior Member
I am not sure to understand correctly the way the ID is generated by EclipseLink.

The default BSON type - stored by MongoDB- for is an ObjectID that is automatically generated by the Java driver and store as a 12bytes in the db.

When I ask my entity to generate the ID for example

 @Id 
 @GeneratedValue()
 @Field(name="_id")
 private String id;


It looks like EclipseLink is using the ID generated by MongoDB Driver but does not store it with the correct format. It is store as a simple string.

For example, with these annotation in the shell, the id looks like:

{ "_id" : "53F740283004D7B7A21DB58E", ...



When generated properly, in the shell it should look like:
{ "_id" : ObjectId("53f73a66300403c9041fda83"), ...



Do I have any way to generate the proper Object ID for MongoDB? (I understand that you can use anything, but I would like to have my Eclipselink application to behave the same way than other FWK)

Also when I have an existing database with some document generate by another application with the proper format, I have no idea how to query -in JQL- it by ID. (since the ID is not a string but an ObjectID). For example in the shell I would use:

db.order.find( { "_id" : ObjectId("53f73a66300403c9041fda83") }  );



So, globally my question is how do we work with ObjectId in EclipseLink?

Re: NoSQL|Mongo : How to use ObjectID ? [message #1709813 is a reply to message #1411128] Thu, 01 October 2015 10:27 Go to previous message
Ray Hulha is currently offline Ray HulhaFriend
Messages: 1
Registered: October 2015
Junior Member
I recently picked up EclipseLink NoSQL plugin development and I used the MongoDB implementation to learn the basics.

So here is the way it generates the ID:


public class OIDSequence extends Sequence {

@Override
public Object getGeneratedValue(Accessor accessor, AbstractSession writeSession, String seqName) {
return new ObjectId().toByteArray();
}

...

}

If this is still important I could try to remove the toByteArray() call and see what happens.

Previous Topic:javax.persistence.sql-load-script-source property is not effective
Next Topic:EclipseLink issue in WLS 12c JPQL query compilation issue: can't be resolved to a valid type
Goto Forum:
  


Current Time: Tue Mar 19 11:23:36 GMT 2024

Powered by FUDForum. Page generated in 0.03980 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top