cześć, staram się za pomocą JSON'a zwrócić listę studentów za pomocą nazwiska nauczyciela. Wszystko wydaję się być ok ponieważ błędu nie ma żadnego lecz rezultatów również nie ma. Problem tak mi się wydaje polega na tym że w zapytaniu w miejscu nazwisko przypisuje się obiekt nauczyciel. Dziekuje za pomoc.
Wywołanie metody:
@POST
@Consumes("application/json")
@Path("/listS")
public NauczycielResponse getlistS (NauczycielRequest request)
{
NauczycielResponse response = new NauczycielResponse();
try {
String requ = String.valueOf(request.getNauczyciel());
dao.listStudents(requ);
response.setSucces(true);
response.setErrorMsg("0");
response.getList();
}
catch (Exception e)
{
response.setErrorMsg(e.getMessage()+"Nie ma takiego rekordu");
response.setSucces(false);
}
return response;
}
Metoda:
public void listStudents(String nazwisko)
{
Session session = HibernateUtil.getSessionFactory().openSession();
Transaction tx = null;
try{
tx = session.beginTransaction();
Query query = session.createQuery("from Student where nauczyciel_id = (select id from Nauczyciel where nazwisko = :nazwisko)");
query.setString("nazwisko", nazwisko);
List<Student> students = query.list();
tx.commit();
for (Iterator iterator1 = students.iterator(); iterator1.hasNext();)
{
Student student = (Student) iterator1.next();
System.out.println("\n");
System.out.print(" ID: " + student.getId() + " First Name: " + student.getImie() + "\n");
}
}catch (HibernateException e) {
if (tx!=null) tx.rollback();
e.printStackTrace();
}finally {
session.close();
}
}
No i NauczycielResponse jeśli to pomoże:
@XmlRootElement
public class NauczycielResponse
{
private String errorMsg;
private boolean succes = true;
private List<Student> list;
public List<Student> getList()
{
list = new ArrayList<Student>();
for (Student s : list)
{
System.out.println("\n");
System.out.print(" ID: " + s.getId() + " First Name: " + s.getImie() + "\n");
}
return list;
}
Mój JSON wygląda tak:
{
"nauczyciel":
{
"nazwisko" : "Kowalski"
}
}