NoSQL|Mongo : How to use ObjectID ? [message #1411128] |
Fri, 22 August 2014 09:10  |
Eclipse User |
|
|
|
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 06:27  |
Eclipse User |
|
|
|
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.
|
|
|
Powered by
FUDForum. Page generated in 0.07717 seconds