• Post Reply Bookmark Topic Watch Topic
  • New Topic

Hibernate: Query with many-to-many  RSS feed

Christopher Olbertz
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody,

can someone explain me how to write a query about a many-to-many relation?

I have the following classes: Person and Category. A person can habe many categories. In Person, there is a set called categories, and in Category, there is a set with the name persons. The primaryKey of Category is called categoryId.

Now, I want to get all persons mit categoryId = 1. I tried the following queries:

1. select p from Person p join p.categories c where c.categoryId = 1

2. select p from Person p, in (p.categories) c where c.categoryId = 1

I get always null, but I know that there is an entity, which has the categoryId = 1.

Can someone help me?
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!