SagittariusA
SagittariusA

Reputation: 5427

Is it possibile to perform JOIN in JPQL?

I'm using Objectdb, an object database, to save Cars to rent and requests for rental. When one customers ask for a rental of a car, I have to check if the car is available in that period (from start date to end date). In my database I have two tables (two classes): car and rent. This is the query to check if the car is available:

public List<Car> findByType(CarType type, Date start, Date end) {

    TypedQuery<Car> query = em.createQuery("SELECT c FROM Car c, Rental r "
            + "WHERE c.type = :cartype AND "
            + "((r.start > :start AND r.start > :end) OR "
            + "(r.end < :start AND r.end < :end))", entityClass);
...

The problem is that this query always return 0 cars available. Is there a problem with a JOIN in JPQL? Or, is the query bad formed? thank you

Upvotes: 0

Views: 112

Answers (1)

ObjectDB
ObjectDB

Reputation: 1308

The query is not a valid JOIN query, because Car c and Rental r are not connected by the query.

But this doesn't explain why you get empty results. Try to isolate the problem by running smaller queries. For example, can you retrieve Rental objects by dates in a Rental only (no Car) query?

Upvotes: 1

Related Questions