Java HQL - excluding rows if 1 to many relationship contains specific value

165 Views Asked by At

Wondering if you could help me out.

I am needing a bit of help using HQL. I currently have two tables, car and carStatus. The car table stores info such as make, model, year etc. The carStatus table contains information on the status of the car, ie crashed, fixed, unfixable etc. In java I have the two tables car and carStatus. Car has a 1 to many relationship with carStatus. What I want to do, using hql is get a list of all the cars where they do not have a carStatus of “crashed”. Is this possible and how would I go about it using hql if it is? The format I am using for HQL is that I have a carRepository which extends springs CrudRepository.

  @Query(“FROM car c WHERE …)
  Car carNotCrashed;

Any help would be greatly appreciated.

1

There are 1 best solutions below

2
On

This might help You

"From Car car left join CarStatus status where status.status != 'Crashed'"