-->
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: Ternary association
PostPosted: Fri Sep 12, 2003 9:17 am 
Newbie

Joined: Mon Sep 08, 2003 8:00 am
Posts: 7
Location: Weiden, Germany
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.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2003 10:51 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
composite elements may be used in queries in Hibernate 2.1

the syntax is exactly the same as for a collection of entities.


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.