Get Mongo db id after insertion in case of POJO class

336 views Asked by At

I have a POJO class in java

@Data
@EqualsAndHashCode(callSuper = false)
@NoArgsConstructor
@AllArgsConstructor
public class TestModel{
    protected ObjectId id;
    private String name;
}

Is there any way to populate id field in case of insertion. I can see that if I use Document, then after insertion I can get objectId by using

document.get("_id");

So is there any way I can achieve same using custom POJO class.

0

There are 0 answers