Hi, guys,
I have users that have roles (n:m). One of the roles is default role, this default "flag" I have placed in association table, so that I can define different role as default role for different users.
I have mapping like this:
<class name="eg.User" table="tbUser"> ... <key column="userActorID"/> <bag name="roles" table="tbUser2Role" lazy="true"> <key column="userActorID"/> <composite-element class="eg.User2Role"> <property name="isDefault" column="isDefault" type="boolean"/> <many-to-one name="role" class="eg.Role" column="tbRoleID"/> </composite-element> </bag> </class>
and DB schema like this:
CREATE TABLE tbRole ( tbRoleID int PRIMARYKEY, administrationavailable smallint NOT NULL DEFAULT 0, )
CREATE TABLE tbUser ( userActorID int PRIMARYKEY, )
CREATE TABLE tbUser2Role ( userActorID int PRIMARYKEY, tbRoleID int PRIMARYKEY, isDefault bit NULL )
everything works fine for the query like this (I get all roles of current user and can analyze contents of the role and identiffy which role is default one):
select elements(user.roles) from User user
but query like this doesn't work:
select user from User user join user.roles where roles.role.administrationavailable = 1
I know that there's somewhere in documentation said that composite elements can not be used in queries!
Question: Is there some alternative way to realize this association so that I can define in User2Role which of the roles associated with user is default role?
thanks and kind regards
reinis.
|