Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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

share|improve this question
    
Do you have a getter method for generalData in the Survey class? –  dnc253 Jul 1 at 14:15

1 Answer 1

ok, dnc253... it was that. thank you. but now i have another problem, very strange. i added a Set in my Survey class (with a getter of course) :

@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)
private GeneralData data;

@OneToMany(cascade = CascadeType.ALL)
private Set<IndexSurvey> index;

...
}

the problem is that i have an exception in JSON result of index when i launch my project in normal mode.

com.sun.jdi.InvocationException occurred invoking method.

But, if i launch it in debug mode, put a break point in the service class to check the content of the index variable, everything is ok

[com.job.model.IndexSurvey@1, com.job.model.IndexSurvey@2, com.job.model.IndexSurvey@3, com.job.model.IndexSurvey@4, com.job.model.IndexSurvey@5]

and the app launches very well with correct datas... it looks like very strange, and maybe i have to wait the response from the service to continue the launching... i don't know, if you have some clue, it would be great !

thanks all

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.