MongoDB / Morphia saves technical id as ObjectId although it's a String in Java

别等时光非礼了梦想. 提交于 2019-12-05 14:44:20

not sure if this is solved yet. I had the same problem. The solution for me was to set the id myself.

@Id
private String id = new ObjectId().toString();

Now you can treat the id field like any other string field.

Hope this helps.

Watsh Rajneesh

I did it slightly differently so i could use the id as path param in REST requests.

@Id
private String id = new ObjectId().toHexString();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!