bluemind
bluemind

Reputation: 1611

How to change which field is used as _id without annotations in Spring data MongoDB

I have some classes which are being generated from a WSDL using the CXF wsdl2java tool. I would like to store instances of these classes in a MongoDB database, using Spring data MongoDB. The default mapping is acceptable for this, except for one thing: I would like to change which field is used as _id.

Normally this is done with a annotation like @Id. But because these classes are generated, I would like to do this without an annotation. Is there a (correct?) way to do this?

So my generated class is:

class Simple {
    String businessId;
    String otherfield1;
    .
    String otherfield999;
}

And I would like Spring data MongoDB to use 'businessId' as the '_id' field in MongoDB, without changing the 'Simple' class by adding an annotation.

Thanks!

Upvotes: 1

Views: 642

Answers (1)

Oliver Drotbohm
Oliver Drotbohm

Reputation: 83161

That's currently not supported. The property either needs to be id, _id or annotated with @Id.

Upvotes: 1

Related Questions