I have 2 calsses: a Unit class and status class. Where Unit class has a List of status. When storring data through java in my Mongodb server, every things go's fine. I tried querying it in console and everything is in there.
The problem how ever is when I use the "same" command in java, it returns all my static data but not my List. Why is that and how can I chanche it?
My Unit class:
@Document(collection = "unit")
public class Unit {
@Field
private int id;
@Field
private long serialNumber;
@Field
private String organisation;
@Field
private List<UnitMeasurementStatus> unitMeasurementStatusList;
/*getters and setters */
}
my unitMeasurementStatus class:
public class UnitMeasurementStatus {
@Field
private Date timeStamp;
@Field
private int value;
/*constructor and getters and setters */
}
my query in console:
db.unit.find({"serialNumber": 0159924843634488}).pretty()
my spring java code:
public void findUnitByLocationId(long serialNumber) {
Query query = new Query();
query.addCriteria(Criteria.where("serialNumber").is(serialNumber));
List<Unit> units = this.mongoTemplate.find(query, Unit.class);
}
I guess if you need a List you should use @DBRef
@DBRef
private List<UnitMeasurementStatus> unitMeasurementStatusList;
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.