HQL: illegal attempt to dereference collection

后端 未结 2 1943
广开言路
广开言路 2020-12-19 07:18

The situation is like this:

I have an entity Book that holds a one-to-many relationship with Chapter.

Now if I try the query, \"from Book book inner jo

相关标签:
2条回答
  • 2020-12-19 07:51

    You can likely do this with a subquery.

    Something like

    from Book book where not exists (from chapter where 
                       chapter.title like '%hibernate%' and chapter.book = book)
    

    (Not tested ...)

    0 讨论(0)
  • 2020-12-19 08:05

    chapters is a collection in books and so will not hold the property title (Collection.title). You need to join the chapters in order to include them in your query like your first example. If your chapters are mapped lazily you will only get a collection of Book's without the chapters loaded in them. So I would say, use your first query.

    For further reading, have a look at the query HQL joins and performance fetching pages.

    0 讨论(0)
提交回复
热议问题