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?