I am having a problem with findAll() method of MongoOperations class when I try to retrieve data from the database . Actually I would like to get the values of the parameters : iliteID, latitude, longitude, height, etc.. Could anyone help out with this issue ?
Thanks in advance .
Here the data structure in the database : (Note : data are entered in a form and saved into the database from a Servlet)
> db.ILites.find().pretty()
{
"_id" : ObjectId("56727fd1b955631adcee6fb1"),
"iLiteID" : "I_Lite1",
"Latitude" : 48.2188,
"Target Power" : 32,
"Status" : "df",
"Ip Address" : "3.3.3.3",
"Longitude" : 11.6248,
"Current Power" : 32,
"Transmission" : "OFF",
"Connectivity" : "we",
"Height" : "23",
"Nominal Message" : "df",
"Emergency Message" : "wrwew"
}
{
"_id" : ObjectId("56728061b955631adcee6fb3"),
"iLiteID" : "I_Lite1",
"Latitude" : 48.2187,
"Target Power" : 43,
"Status" : "dg",
"Ip Address" : "2.2.2.2",
"Longitude" : 11.6247,
"Current Power" : 43,
"Transmission" : "ON",
"Connectivity" : "dgdf",
"Height" : "34",
"Nominal Message" : "cb",
"Emergency Message" : "gdf"
}
Here the java code:
protected List<ILites> getAllILites(){
ApplicationContext ctx = new AnnotationConfigApplicationContext(SpringMongoConfig.class);
MongoOperations mongoOperation = (MongoOperations) ctx.getBean("mongoTemplate");
List<ILites> ilites = mongoOperation.findAll(ILites.class, "ILites");
System.out.println("#3 for advance");
for (ILites temp : ilites) {
// I am getting an "null" value instead of the value of the longitude
System.out.println(temp.getLongitude());
//This displays something like this : mongodb.model.ILites@732cbcd5 (which i don't really understand)
System.out.println(temp);
}
return ilites;
}
SprinMongoConfig Class
@Configuration
public class SpringMongoConfig {
public @Bean MongoDbFactory mongoDbFactory() throws Exception {
return new SimpleMongoDbFactory(new MongoClient(), "ILiteDB");
}
/**
*
* @output MongoTemplate
* @description
*/
public @Bean MongoTemplate mongoTemplate() throws Exception {
final MappingMongoConverter converter = new MappingMongoConverter(
mongoDbFactory(), new MongoMappingContext());
/**
* To remove "_class" field in collection which is useless and added by
* default
*/
converter.setTypeMapper(new DefaultMongoTypeMapper(null));
final MongoTemplate mongoTemplate = new MongoTemplate(mongoDbFactory(),
converter);
return mongoTemplate;
}
}
Spring Controller Class
/**
*
* @output ModelAndView
* @description redirect to dashboard
*/
@RequestMapping(value = "/adminDashboard", method = RequestMethod.GET)
public ModelAndView adminPage() {
userDao.updateLastLogin(getCurrentUser());
final ModelAndView model = new ModelAndView();
model.addObject("iLiteList", getAllILites());
model.setViewName("adminDashboard");
return model;
}
Entity Class
@Document(collection = "ILites")
public class ILites {
private String status;
private String ipAddress;
private String transmission;
private String connectivity;
private String emergencyMessage;
private String nominalMessage;
//private String manualCommand;
private Double latitude;
private Double longitude;
private Double currentPower;
private Double targetPower;
private Double height;
/**
* Primary key - Unique Identifier
*/
@Id
private String iLiteID;
public ILites(final String iLiteID, final String status,final String ipAddress,
final String transmission, final String connectivity,final String emergencyMessage,
final String nominalMessage, final Double latitude,
final Double longitude, final Double currentPower,final Double targetPower,final Double height) {
super();
this.iLiteID = iLiteID;
this.status = status;
this.ipAddress = ipAddress;
this.transmission = transmission;
this.connectivity = connectivity;
this.emergencyMessage = emergencyMessage;
this.nominalMessage = nominalMessage;
//this.manualCommand = manualCommand;
this.longitude = longitude;
this.latitude = latitude;
this.currentPower = currentPower;
this.targetPower = targetPower;
this.height = height;
}
public Double getHeight() {
return height;
}
public void setHeight(Double height) {
this.height = height;
}
public String getILiteID() {
return iLiteID;
}
public void setILiteID(String iLiteID) {
this.iLiteID = iLiteID;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getIpAddress() {
return ipAddress;
}
public void setIpAddress(String ipAddress) {
this.ipAddress = ipAddress;
}
public String getTransmission() {
return transmission;
}
public void setTransmission(String transmission) {
this.transmission = transmission;
}
public String getConnectivity() {
return connectivity;
}
public void setConnectivity(String connectivity) {
this.connectivity = connectivity;
}
public String getEmergencyMessage() {
return emergencyMessage;
}
public void setEmergencyMessage(String emergencyMessage) {
this.emergencyMessage = emergencyMessage;
}
public String getNominalMessage() {
return nominalMessage;
}
public void setNominalMessage(String nominalMessage) {
this.nominalMessage = nominalMessage;
}
/*public String getManualCommand() {
return manualCommand;
}
public void setManualCommand(String manualCommand) {
this.manualCommand = manualCommand;
}
*/
public Double getLatitude() {
return latitude;
}
public void setLatitude(Double latitude) {
this.latitude = latitude;
}
public Double getLongitude() {
return longitude;
}
public void setLongitude(Double longitude){
this.longitude = longitude;
}
public Double getCurrentPower() {
return currentPower;
}
public void setCurrentPower(Double currentPower) {
this.currentPower = currentPower;
}
public Double getTargetPower() {
return targetPower;
}
public void setTargetPower(Double targetPower) {
this.targetPower = targetPower;
}
}