0

how can I do this :

SELECT c.categoriesThemes FROM Categorie c WHERE c.url = :url AND c.categoriesThemes.id != 5

This is problematic : c.categoriesThemes.id != 5

thank you in advance

3 Answers3

0
SELECT c.categoriesThemes FROM Categorie c WHERE c.url = :url AND c.categoriesThemes.id <> 5
Joachim Rohde
  • 5,915
  • 2
  • 29
  • 46
  • down vote accept Thanks a lot but i have this error : org.hibernate.QueryException: illegal attempt to dereference collection [categorie0_.id.categoriesThemes] with element property reference [id] [SELECT c.categoriesThemes FROM com.warez.iodos.model.Categorie c WHERE c.url = :url AND c.categoriesThemes.id <> 5] – Thomas Delizee Mar 20 '17 at 16:12
  • While this code snippet may solve the question, [including an explanation](http://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. – DimaSan Mar 20 '17 at 17:54
0

Presuming the item type you want is CategoryTheme and the category's property name is category, you'd need a query kind of like this

SELECT ct FROM CategoryTheme ct WHERE ct.category.url = :url AND ct.id <> 5

Basically, you are trying to select from the wrong table.

coladict
  • 4,799
  • 1
  • 16
  • 27
0

So, i have create a bidirectionnel and now, this request is ok

SELECT ct FROM CategorieTheme ct JOIN ct.categorie c WHERE c.url = :url AND ct.id <> 5

But not this :

SELECT c.categoriesThemes FROM Categorie c JOIN c.categoriesThemes ct WHERE c.url = :url AND ct.id <> 5

Why ?