Greetings,
Is it at all possible to initialize a collection of string values using a custom sql query?
I have a User object that has a Set of String values, named roles, which I need to populate when the User object is retrieved. However certain conditions in other tables dictate which values will be included in the Set, so I need to to do some custom sql.
Code:
public class User
{
private Set<String> roles;
..getters and setters
}
I have been attempting to map the User roles like so:
Code:
<set name="roles" inverse="true" lazy="false">
<key/>
<element type="string" />
<loader query-ref="userRoles"/>
</set>
With a (simplified) custom query:
Code:
<sql-query name="userRoles">
<load-collection alias="role" role="User.roles" />
select distinct {role.role_name_fk} from user_role role where role.user_name_fk = ?
</sql-query>
From what I can gather the <load-collection> can only work with defined entities, and since I have a Set of strings it won't work for me.
I've been experimenting with different configurations with no luck. Basically I just need to know whether it is possible to achieve this using Hibernate mapping.
Thanks,
Alan.