• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

HQL: illegal attempt to dereference collection

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 join book.chapters chapter where chapter.title like '%hibernate%'", it gives me the desired result.

But if I try, "from Book where book.chapters.title like '%hibernate%'", I get the error illegal attempt to dereference collection.

The thing is that I only want the collection of Book objects in return and not a collection of pair of Book and Chapter objects in return which I get with the former query.

Could someone help me understand?
 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello.
You can also try with: "select distinct ch.book from Chapter ch where ch.title like '%hibernate%'"
 
Ranch Hand
Posts: 62
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

But if I try, "from Book where book.chapters.title like '%hibernate%'", I get the error illegal attempt to dereference collection.



This would not work... as its something like book.getChapters().getTitle() .. as as book.getChapters() returns a collection, the getTitle fails.
 
Rohit Bhal
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@joy: I think query like "...book.chapters.title..." is not supported anymore. I am not sure if it was supported in the older version of Hibernate either. Thanks for reply

@Bogdan: Yes, "select book from Book book inner join book.chapters chapter where chapter.title like '%Hibernate%'" gave me exactly that. Thanks for reply
 
Shiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic