angularjs - How to preform the JOIN FETCH query to get the correct result? -
ok guys, got this:
a student id, name , last name...
now created new java class called accounts
id, name , value
there this:
@onetomany(cascade = { cascadetype.all}) private set<bankaccout> accounts; public student() { accounts= new hashset<bankaccout>(); } public set<bankaccout> getaccounts() { return accounts; } public void setaccounts(set<bankaccout> accounts) { this.accounts= accounts; }
now, have site, on site there table data of students... unique
then had write new class, , have add listbox site, shows selected students accounts...
my old query calling student looked this:
@get @path("/getall") @produces(mediatype.application_json) public list<student> getall() { return em.createquery("from student s").getresultlist(); }
and controller looks this:
$http.get('http://localhost:8080/creditcardweb/rest/cc/getall').success( function(data) { $scope.result = data; });
and worked...in table there no problems....but had change query able bind data accounts table....and query looks this...
return em.createquery("from student s inner join fetch s.accounts").getresultlist();
and now, table should show me same data before...that is, students unique....but shows me students have @ least 1 account....and not that, same student shown not once, more times (the number has accounts) in table...
any suggestions?
an inner join
filters off records either table not match. hence, current join removing students not have account. way around use left join
, retain students if not have account:
return em.createquery("from student s left join fetch s.accounts").getresultlist();
Comments
Post a Comment