I have the following Java Pojo part of an application I am making:
@Document
public class Resume implements ResumePlan,Serializable {
private static final long serialVersionUID = -5332235643191283709L;
@Id
private String id;
@Autowired(required=false)
private Objective objective;
@Autowired
private PersonalDetails personalDetails;
@Autowired
private Skills skills;
@Autowired(required=false)
private Experience experience;
@Autowired
private Education education;
@Autowired(required=false)
private References references;
@Autowired(required=false)
private Publications publications;
}
I am saving it by the following code:
mongoOperations.insert(resume);
When I check on the backend in the mongodb console: following is getting stored:
db.resume.find(); { "_id" : "test@abc.com+919876543210", "_class" : "com.springmyresume.resume.Resume" }
It is not storing the rest of the bean objects like PersonalDetails etc..
Can someone tell me what I am doing wrong here.
It is solved. I made the following changes. 1) Removed @Autowired annotation 2) Added @DBRef annotation With the @Autowired annotation the field objects were not getting saved. I don't know why this is the behaviour.
First please make sure that you have all necessary fields' classes ( Objective
, PersonalDetails
) annotated as @Document
.
For second, please provide getters and setters for fields objects.
Also please make sure, that you have specified actual @Id
, otherwise spring will do it for you.
BTW, if you would like to not use embedding, you may use @DBRef
annotation. Here is quite good information:
http://maciejwalkowiak.pl/blog/2012/04/30/spring-data-mongodb-cascade-save-on-dbref-objects/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.