Hi dear Hibernate-forum
First things first: I am a Hibernate newbie and not a native english speaker. So please be just a little forgiving?
I feel lost about a (simple?) problem. Actually it is kind like the inverse of this post:
http://forum.hibernate.org/viewtopic.ph ... d3e83e4627
By inverse I mean that what the mentioned poster does not want, is what I want :)
I am using XML definitions, not annotations (which also is "inverse" to the above mentioned post). And I have a class "User" (table users) that has a many-to-many-association to a class "Role" (table roles). The intermediate mapping table is called user_roles.
Now the table roles has an attribute called active. What I want is that the class "User" only contains "Roles" that have the active attribute set to 1.
My mapping looks like this:
Code:
<class name="User" table="users">
...
<set name="roles" table="user_roles" lazy="false"
where = "active = 1" cascade="none">
<key column="userId" />
<many-to-many column="roleId"
class="foo.bar.Role" />
</set>
</class>
What hppens now is that Hibernate generates a query where it includes a
Code:
"user_roles.active = 1"
in the SQL. This, of course, does not work. The "active" attribute is in the roles-table, not in the user_roles...
Now I understand that when using annotations there is a @where and a @wherejointable to distinguish exactly this. Does something similar exist for XML definitions? Or do I have to place the where-condition somewhere else?
I do not want to exclude all roles not having active = 1 from my application completely. Admin-functionality for example needs to see all roles (including the ones having active = 0).
Thanks for any help, pointer, rtfm-hint (I tried the friendly manual but whithout any luck), the right google-query, whatever...
Kind regards
scherand