Your code uses scala constructs in an interesting way. Which might not lead to correct results. The for comprehension in
for(srchStd <- searchstudent){
var sid= srchStd.getStudent().getId()
studentsearch = studentTestService.findAllStudentTestByStudent(sid)
}
reassigns studentsearch
in each iteration to a new value, so in the end it is set to the value of the last iteration. If you want to accumulate the results something like
import scala.collection.JavaConversions._
val searchstudent = parentStudentService.findParentStudentByParent(z)
val testResult = searchstudent.flatMap{ srchStd =>
val sid = srchStd.getStudent().getId()
studentTestService.findAllStudentTestByStudent(sid)
}
will result in all tests collected in testResult
.
The import of scala.collection.JavaConversions._
helps converting between scala and java collections. More information can be found here: http://www.scala-lang.org/api/current/index.html#scala.collection.JavaConversions$.