-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Many-to-many with where clause in xml definition
PostPosted: Sun Apr 06, 2008 8:43 am 
Newbie

Joined: Sun Apr 06, 2008 8:16 am
Posts: 1
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.