2

I have been using Spring-Data-Mongo for a while now on a project without issues. In the last POM update, I started seeing the following exception in the log file:

WARN : 04 Aug 2014 13:55:24 org.springframework.data.mongodb.core.mapping.BasicMongoPersistentProperty - Customizing field name for id property not allowed! Custom name will not be considered!

It does not provide any clue as to where this issue arises so we are clueless. It is repeated several times as calls to the app are made. We did find the origin of this here: https://github.com/spring-projects/spring-data-mongodb/blob/11417144bd3574c35af06fde3a3c2e56a1dd5890/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/BasicMongoPersistentProperty.java#L85

Any ideas?

Edit: Added example class for those interested:

@Document(collection="Account")
public class Account {
    ....
    @Id
    private String id = null;
    ....
}
5
  • Don't provide link to class, post the code. Also, how about showing us YOUR code instead of Spring's? Commented Aug 4, 2014 at 12:06
  • 1
    I cannot post my complete project code! The exception generated by Spring does not provide any clue as to which field etc. Contributers: can you add something to the exception for next release? @John B - please remove your downvote as it is irrelevant in this case. Commented Aug 4, 2014 at 12:21
  • Post example code showing how you have defined the ID field in your class. Commented Aug 4, 2014 at 12:28
  • I have tens of classes and there is no issue there. Commented Aug 4, 2014 at 12:32
  • 1
    @checklist I agree - a more descriptive error message would go a long way here. I had to track down my error by setting a debugger breakpoint in spring-data-mongodb code Commented Feb 19, 2017 at 17:52

2 Answers 2

5

I listened to the nice comments above and put a breakpoint on . I quickly found out that one of my classes was using the following:

@Id
private String Id;

Note the Id instead of id. Once changed, the warning disapearind.

I fully support the suggestion to have spring-data provide a proper report rather than simply a meaningless warning.

Sign up to request clarification or add additional context in comments.

1 Comment

Yup - my issue was a similar subtle issue. The warning actually detected an error in my code, it just gave no help as to where
2

My thought is that you are trying to use @Id with @Field on the same field. This is not allowed since the id field in Mongo must be called _id. Anything further is hard to tell since you didn't post your code.

1 Comment

That was also my thought. But the only place we use @Field is on a Spring-Data-Solr document. I have also tried removing those but the exception did not go away.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.