-->
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.  [ 2 posts ] 
Author Message
 Post subject: Using a filter as a foreign key in a set?
PostPosted: Thu Mar 02, 2006 3:40 pm 
Newbie

Joined: Thu Mar 02, 2006 3:20 pm
Posts: 2
Hopefully this is a simple question to answer; I have:

Code:
<set name="domainpref" table="USERPREF" order-by="prefid asc">
<key column="USERNAME" property-ref="username"/>
<one-to-many class="Userpref"/>
<filter name="domainPrefFilter" condition="CONCAT('%',:domain) = USERNAME"/>
</set>


...and in my code I just drop...

Code:
sess.enableFilter("domainPrefFilter").setParameter("domain",user.getDomain());
Set domainpref = user.getDomainpref();


What I'm trying to accomplish is loading a set into a user based upon their domain-- in essence, the foreign key should be based upon the CONCAT statement. A value of user@mydomain.com in the username column is a valid user preference (which I have as another set) but a value of %mydomain.com in the username column is a domain preference for any user in that domain. As you might expect, the above mapping doesn't work due to the following SQL being generated:

Code:
select domainpref0_.USERNAME as USERNAME1_, domainpref0_.prefid as prefid1_, domainpref0_.prefid as prefid7_0_, domainpref0_.preference as preference7_0_, domainpref0_.value as value7_0_ from USERPREF domainpref0_ where  CONCAT('%',?) = domainpref0_.USERNAME and domainpref0_.USERNAME=? order by domainpref0_.prefid asc


The desired select statement does not include the domainpref0_.USERNAME=? condition.

Taking the key line out of the set obviously breaks things. Is there any way to use the filter as the foreign key of the set? If not, is there any way I can dynamically specify the foreign key?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 02, 2006 4:16 pm 
Newbie

Joined: Thu Mar 02, 2006 3:20 pm
Posts: 2
Well, I created a workaround for my problem, but I'm not sure if it's the "right" thing to do. In my original user object, I have:

Code:
<property name="prefdomain" formula="CONCAT('%',SUBSTRING(username,INSTR(username,'@')+1))"/>


Then I changed my set to look like:

Code:
<set name="domainpref" table="USERPREF" order-by="prefid asc">
<key column="USERNAME" property-ref="prefdomain"/>
<one-to-many class="Userpref"/>
</set>


This seems like a bit of a kludge to have to run something at select time in order to have an arbitrary foreign key.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.