Reputation: 19
I am a beginner in Hibernate
. I want to select data from two tables using hql
.
the problem is that the query gives me result if I select one object like this example:
(select d from eresa e, dresa d where e.f_ideResa = d.eresa.f_ideResa and e.F_DATEFROM=:x)
but when i want to select multiples data from 2 two tables like this :
(select e.f_ideResa, d.F_PAXNAME from eresa as e, dresa as d where e.f_ideResa = d.eresa.f_ideResa and e.F_DATEFROM=:x ");)
it gives me error:
Etat HTTP 500 - java.lang.NumberFormatException..
Upvotes: 0
Views: 3447
Reputation: 5325
If both tables have relationship then use join to fetch data using join we use
select e.f_ideResa, d.F_PAXNAME from eresa as e
left join fetch e.dresa as d
where
e.F_DATEFROM=:x "
dresa
is propery in Pojo classs eresa
You must check f_ideResa
,F_PAXNAME
,F_DATEFROM
must be field names in Pojo class
For more details see
Upvotes: 2
Reputation: 19
I think I shoud to use arraylist instead list
public List<eresa> getDetailparDateArrive(Date date) {
// TODO Auto-generated method stub
Session session=HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
// Query req=session.createQuery("from eresa e inner join dresa d on e.f_ideResa = d.eresa.f_ideResa and e.F_DATEFROM=:x ");
Query req=session.createQuery("from eresa e, dresa d where e.F_DATEFROM=:x and e.f_ideResa = d.eresa.f_ideResa ");
req.setParameter("x", date);
return req.list();
}
Upvotes: 1