I have written the follwoing jpql query which is inserting a cross join between my entities. How do I avoid that?

15 views Asked by At

I have two entities Bikes and Cart, which have many to many relation between them. I want to find all the bikes from the cart of some specific user.

The query is as follows: select distinct new com.bike.dto.CartBikeDTO(b.id, b.name, b.price, c.bikeQuantity, b.bikeType, b.bikeBrands, b.colour, b.imagePath) from Bikes b join b.bikeCartSet, Cart c where c.thisCartCustomer =:user

The hibernate conversion of the above query inserts a cross join between bikeCartSet and Cart due to which I am getting multiple repetitive results. How can I avoid that?

I tried changing the order i.e. taking Cart as the primary entity but to now avail. The repetitive rows are still being fetched.

0

There are 0 answers