-->
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.  [ 5 posts ] 
Author Message
 Post subject: Using filters on Sets
PostPosted: Mon Dec 12, 2005 11:45 am 
Newbie

Joined: Mon Dec 12, 2005 11:37 am
Posts: 14
I am trying to use hibernate filters on sets.

My example mapping is:

<class name="ConnectRole" table="CONNECTROLE">
<id name="roleId" column="ROLE_ID" type="string">
<generator class="uuid"/>
</id>
<property name="roleName" column="ROLE_NAME"/>
<property name="roleDesc" column="ROLE_DESC" length="1024"/>
<set name="users" table="USERROLES" lazy="false" fetch="select">
<key column="roleId"/>
<many-to-many column="userId" class="ConnectUser"/>
<filter name="activeItem" condition=":active = ACTIVE"/>
</set>
<property name="active" column="ACTIVE" type="boolean"/>
<filter name="activeItem" condition=":active = ACTIVE"/>
</class>

<class name="ConnectUser" table="CONNECTUSER">
<id name="userId" column="USER_ID" type="string">
<generator class="uuid"/>
</id>
<property name="userName" column="USER_NAME" unique="true"/>
<property name="password" column="USER_PASSWORD"/>
<map name="userAttributes" table="USER_ATTRIBUTES" fetch="join" lazy="false">
<key column="USER_ID"/>
<map-key column="ATTR_NAME" type="string"/>
<element column="ATTR_VALUE" type="string"/>
</map>
<set name="roles" table="USERROLES" lazy="false" fetch="select">
<key column="userId"/>
<many-to-many column="roleId" class="ConnectRole"/>
<filter name="activeItem" condition=":active = ACTIVE"/>
</set>
<property name="active" column="ACTIVE" type="boolean"/>
<filter name="activeItem" condition=":active = ACTIVE"/>
</class>

And the filter is:

<filter-def name="activeItem">
<filter-param name="active" type="boolean"/>
</filter-def>

So basically I have a Role.users (set) that I would want to get filtered. However, the SQL that hibernate generates puts the filter condition on the association table instead on the entity table.

Hibernate: select connectuse0_.USER_ID as USER1_, connectuse0_.USER_NAME as USER2_3_, connectuse0_.USER_PASSWORD as USER3_3_, connectuse0_.ACTIVE as ACTIVE3_ from CONNECTUSER connectuse0_ where ? = connectuse0_.ACTIVE and connectuse0_.USER_NAME like 'ft%'
Hibernate: select roles0_.userId as userId__, roles0_.roleId as roleId__, connectrol1_.ROLE_ID as ROLE1_0_, connectrol1_.ROLE_NAME as ROLE2_0_0_, connectrol1_.ROLE_DESC as ROLE3_0_0_, connectrol1_.ACTIVE as ACTIVE0_0_ from USERROLES roles0_ inner join CONNECTROLE connectrol1_ on roles0_.roleId=connectrol1_.ROLE_ID where ? = roles0_.ACTIVE and roles0_.userId=?

Is that a bug?


Top
 Profile  
 
 Post subject: ?
PostPosted: Mon Dec 12, 2005 6:33 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
It looks like H applies the filter to the entity table too:

Hibernate: select connectuse0_.USER_ID as USER1_, connectuse0_.USER_NAME as USER2_3_, connectuse0_.USER_PASSWORD as USER3_3_, connectuse0_.ACTIVE as ACTIVE3_ from CONNECTUSER connectuse0_ where ? = connectuse0_.ACTIVE and connectuse0_.USER_NAME like 'ft%'

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 13, 2005 10:47 am 
Newbie

Joined: Mon Dec 12, 2005 11:37 am
Posts: 14
The relationship is

ConnectUser <- UserRoles -> ConnectRole

The filter that you saw is on teh first part because that was the direction of the query.

Basically, here is what I need:

Both the User and Role tables have a column called "ACTIVE".

I want to do a User.getRole(); and want only the active roles to be returned- which is where it fails.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 30, 2005 7:15 am 
Beginner
Beginner

Joined: Thu Dec 01, 2005 12:53 am
Posts: 21
I am aslo facing same problem.... did anyone find the solution ... or migration to 3.1 would that fix it? .. using 3.0 currently.. I also see a jira issue for this one http://opensource2.atlassian.com/projec ... se/HHH-229


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 30, 2005 7:38 am 
Beginner
Beginner

Joined: Thu Dec 01, 2005 12:53 am
Posts: 21
I think I myself figure this out...

Instead of placing filter tag inside the set tag put it inside the many-to-manytag like this ...

Code:
<set name="Accounts" table="user_account" cascade="none">
         <key column="user_id" />
         <many-to-many column="account_id" class="com.foo.Account" >
            <filter name="isActiveFilter"
                   condition=":isActive = is_active"/>                        
         </many-to-many>
</set>


Above works for me in 3.0


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

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.