Can you help me with two hibernate queries? I have these tables:
Record:
Code:
Id(INT)
Id_car(INT)
Id_user(INT)
date_start(DATE)
date_end(DATE)
status(VARCHAR)
Cars:
Code:
Id
Id_manufacturer(VARCHAR)
model(VARCHAR)
power(VARCHAR)
speed(VARCHAR)
fuel(VARCHAR)
price(VARCHAR)
active(VARCHAR)
Manufacturer:
Code:
Id
name
Now i need to output all cars that aren't currently rented (they aren't in table record or if they are in table record then atribute "status" in tbl_record should have value finished)
Second query is for search of free cars in some period (user forward two dates and then it should output all cars that aren't in table record or cars that are in tbl_record, but they don't have status="reserved" in that period that user forward)
Here is my query for output all cars:
Code:
String hql= "FROM Cars as c left join fetch c.manufacturer as m";
this string i use in CarDaoImpl.java
Code:
@Override
public List<Cars> freeCars() {
List<Cars> l= null;
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
String upit = "FROM Cars as c left join fetch c.manufacturer as m";
try {
session.getTransaction().begin();
l = session.createQuery(upit).list();
session.getTransaction().commit();
} catch (Exception e) {
session.getTransaction().rollback();
}
return l;
}