-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: I need help with two queries
PostPosted: Mon Jan 02, 2017 11:32 am 
Newbie

Joined: Mon Jan 02, 2017 11:24 am
Posts: 1
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;
    }


Top
 Profile  
 
 Post subject: Re: I need help with two queries
PostPosted: Mon Jan 09, 2017 6:46 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Check out the Hibernate User Guide HQL chapter. Since you haven't provided any mapping and no query that you attempted but that haven't worked, I assume you are better off if you read all the documentation first since it will surely answer more than just this question.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.