[JAVA-2955] ObjectId created in java code not inserted to document Created: 31/Aug/18 Updated: 27/Oct/23 Resolved: 03/Sep/18 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | Codecs, POJO |
| Affects Version/s: | 4.0.0 |
| Fix Version/s: | None |
| Type: | Task | Priority: | Minor - P4 |
| Reporter: | Ahmad Thahir | Assignee: | Unassigned |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Windows 7 64 Bit, mongodb-driver 3.8.1 |
||
| Description |
|
Halo, I tried inserting data through POJO, I made my own ObjectId in the POJO object with the code as below : ObjectId oid = ObjectId.get(); res.set_id = oid; resCollection.insertOne(res); the problem arises when I check the results of ObjectId, it is not the same as the code created with the data entered in the document, after I do the experiment, I see that the error is in the getter naming for ObjectId, here are the results: getId -> result : ObjectId created is same as the one entered in the document getid -> resutl : ObjectId in document not the same as the code created get_Id -> resutl : ObjectId in document }}{{ not the same as the code created get_id -> resutl : ObjectId in document }}{{not the same as the code created
from the three getter naming that failed to insert ObjectId to document, I don't see any additional fields in the collection (id, _Id), I am not sure this is a bug or not, but I think that this explanation is very necessary I also did some tests, my conclusion, the three getter naming that failed to enter the ObjectId to document, actually read by the POJO codec, but ignored & ObjectId was finally created by mongodb server Thanks Thahir
|
| Comments |
| Comment by Ross Lawley [ 03/Sep/18 ] |
|
Thanks for the ticket. The PojoCodec requires properties to follow Java Bean convention and as the getid, get_Id and get_id properties do not follow the Java Bean convention they are ignored. Custom PropertyModelBuilder instances could be added to the ClassModelBuilder to support these fields but it is not something that is supported by default. Just to let you know for future reference, this project is for Java driver bugs or feature requests. The best place for questions regarding MongoDB usage or the Java driver specifics is the mongodb-user mailinglist or stackoverflow as you will reach a boarder audience there. If your business requires an answer from MongoDB within a time frame then we do offer production support. All the best, Ross |