Cześć. Tworzę aplikację REST Api w której za pomocą odpowiednich końcówek chcę wyciągać z bazy odpowiednie dane.
Posiadam metodę która wyświeta z tabeli wszystkie rekordy w postaci listy
@Override
public List<City> findAll() {
// get the current hibernate session
Session currentSession = entityManager.unwrap(Session.class);
// create a query
Query<City> theQuery = currentSession.createQuery("from City", City.class);
// execute query and get result list
List<City> cities = theQuery.getResultList();
// return the results
return cities;
}
I wszystko gra, po wejściu w odpowiedni link wyświetla się lista miast
Jednak kiedy próbuje troszke skomplikować to zapytanie
@Override
public List<City> findAllCitiesRidesGoesFrom() {
Session currentSession = entityManager.unwrap(Session.class);
Query<City> theQuery = currentSession.createQuery("SELECT DISTINCT city.id_city, city.city_name FROM city, ride WHERE ride.id_city_from = city.id_city", City.class);
List<City> cities = theQuery.getResultList();
return cities;
}
dostaje błąd "org.hibernate.hql.internal.ast.QuerySyntaxException: city is not mapped" i wskazuje, że coś jest nie tak z zapytaniem
To samo zapytanie złożone w MySQL Workbenchu daje taki wynik
Wiecie może o co tu chodzi ? Co jest nie tak w tym zapytaniu ?