I have two testing tables associated by foreign key
- table
School(with fk onstudent_id) - table
Students(with pk onid) - FK:
school.student_id -> students.id
How can I get students name using this query?
Session session = DaoSF.getSessionFactory().openSession();
String query = "";
Query criteria;
query = "from School s " +
"inner join s.student st " +
"where s.student_id = st.id";
criteria = session.createQuery(query);
When I try to iterate data:
for(Iterator<?> iter = criteria.iterate(); iter.hasNext();)
{
Object item = (Object)iter.next();
System.out.println(((School) item).getStudent().getId());
}
it reports:
Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to table.School
but mapping is working, because when i've changed the last row to
System.out.println(item.toString());
I've got all the data but like that:
[Ljava.lang.Object;@1d2300e
[Ljava.lang.Object;@51207c
[Ljava.lang.Object;@2bd615
...
Query criteriauses?