Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Object Relational Mapping and the fly likes Hibernate many-to-many error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate many-to-many error" Watch "Hibernate many-to-many error" New topic

Hibernate many-to-many error

Wagner Danda Da Silva Filho
Ranch Hand

Joined: Mar 21, 2003
Posts: 80
Hi All,

I'm having trouble to query a many-to-many association with Hibernate. Here are the envolved hbm files:

Here are the classes:

Here is the Criteria I'm trying to create:

Here is the output:

I could see that Hibernate is doing a SELECT in the wrong table! The many-to-many table is "PACP_PACOTE_PLANO", and the select is reading from "PACM_PACOTE_MINUTOS"...

What am I doing wrong?
[ September 09, 2005: Message edited by: Wagner da Silva ]

Wagner Danda Da Silva Filho
Ranch Hand

Joined: Mar 21, 2003
Posts: 80
Hey, I found a stupid yet simple solution:

First I get a "PlanoFaturamento" object loaded from my DAO, e.g.:

Then I can simply call:

This executes the correct query and gives me a Collection of "PacoteMinutos".
It is sorta covered in the JavaRanch Style Guide.
subject: Hibernate many-to-many error
Similar Threads
joined-subclass problem
Hibernate one-to-many inner join?
Error in Oracle LONG mapping
Incorrect joins on composite ID
Hibernate Select - Criteria with a Date