here is my problem. i created a small project in java + spring mvc + hibernate + angularJS. i would like to display data from my Oracle DB.
i have those two objects :
@Entity
public class Survey {
@Id
@GeneratedValue
private int id;
private String fileReference;
private String typeFile;
private String prm;
private String status;
private String refGinkoAffair;
private String contratOwner;
private String fournisseur;
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private GeneralData generalData;
...
}
and this one :
@Entity
public class GeneralData {
@Id
@GeneratedValue
private int id;
@OneToOne(mappedBy = "generalData")
private Survey survey;
private String comments;
private String matricule;
@Enumerated(EnumType.STRING)
@Column(name = "customer_type")
private CustomerType customerType;
...
}
to get the datas from my DB, i use these controller, with search this method :
@Controller
@RequestMapping(value = "/protected/originalSurvey")
public class OriginalSurveyController {
@Autowired
private SurveyService surveyService;
@Autowired
private MessageSource messageSource;
@RequestMapping(method = RequestMethod.GET)
public ModelAndView originalSurvey() {
return new ModelAndView("originalSurvey");
}
@RequestMapping(value = "/{fileReference}", method = RequestMethod.GET, produces = "application/json")
public ResponseEntity<?> search(@PathVariable("fileReference") String fileReference,
@RequestParam(required = false, defaultValue = "0") int page, Locale locale) {
return search(fileReference, page, locale, null);
}
private ResponseEntity<?> search(String fileReference, int page, Locale locale, String actionMessageKey) {
SurveyList surveyList = surveyService.findByFileReferenceLike(page, 1, fileReference);
if (!StringUtils.isEmpty(actionMessageKey)) {
addActionMessageToList(surveyList, locale, actionMessageKey, null);
}
Object[] args = { fileReference };
addSearchMessageToList(surveyList, locale, "message.search.for.active", args);
ResponseEntity<SurveyList> responseEntity = new ResponseEntity<SurveyList>(surveyList, HttpStatus.OK);
return responseEntity;
}
and finally, i have these script in my file.js to get the data :
var config = {};
config.params.page = $scope.pageToGet;
config.params.searchFor = $scope.searchFor;
$http.get(url, config)
.success(function (data) {
$scope.finishAjaxCallOnSuccess(data, "#searchRapportsModal", isPagination);
$scope.displaySearchMessage = true;
})
.error(function(data, status, headers, config) {
$scope.handleErrorInDialogs(status);
});
So, the problem is quite simple, my var data is almost correct. In Fact, i don't have the generalData mapped in the object data... when i looked into the JSon response, i have this :
survey Object { id=1, status="actif", fileReference="0112547", more...}
id 1
status "actif"
refGinkoAffair null
fileReference "0112547"
typeFile null
contratOwner "moi"
fournisseur "erdf"
prm "prm1"
As you can see, the generalData object is even not there ! the surprising thing is that the ResponseEntity Object in the java controller contains the generalData object ! i think it's the json mapping between my java file and my file.js who's incorrect, but i really don't know how to fix it
i hope i'm clear on what i'm looking for, and i reaaly hope someone can help me.
thanks you
generalData
in theSurvey
class? – dnc253 Jul 1 at 14:15