-->
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.  [ 5 posts ] 
Author Message
 Post subject: Cross-table mapping
PostPosted: Mon Dec 08, 2003 10:34 am 
Newbie

Joined: Thu Dec 04, 2003 11:59 am
Posts: 11
I have an object (AutorizedUser), it has an count (numberOfRoles) attribute which used to count the roles this user has and is pointed to another table (Roles).
In my query, I need to grab this user object from User table as well as grab the count of it primary key appeared in the Roles table.
Could any one help me in the mapping and the HQL?
Much thanks.
George


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 08, 2003 11:06 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
If you mean count is a column of a different table than the one you used to save AutorizedUser, then you cannot map 1 class into several tables.

But I'm confused about what you want to do.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 08, 2003 11:33 am 
Newbie

Joined: Thu Dec 04, 2003 11:59 am
Posts: 11
Count is not a column in another table (Roles), it is to count how many roles a particular user has in the Roles table.
I have a Users table and a Roels table. A user may have 0 to many roles, it is an one-to-many mapping. In the application, I don't need to load user with all roles, instead I only want to know how many roles this user has. The idea is to select all user fields from User table with given criteria and select count(*) from Role table where userId=givenUserId.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 08, 2003 3:46 pm 
Beginner
Beginner

Joined: Fri Aug 29, 2003 12:38 am
Posts: 22
Location: Phoenix, AZ
I belive you could use a "formula" or computed property using "select count(*) from table where [where condition]" as the formula

http://www.hibernate.org/hib_docs/refer ... pping-s1-7

(excerpt)
Code:
<property
        name="propertyName"                 
        column="column_name"               
        type="typename"                     
        update="true|false"                 
        insert="true|false"                 
        formula="arbitrary SQL expression" 
        access="field|property|ClassName"   
/>

...
Code:
formula (optional): an SQL expression that defines the value for a computed property. Computed properties do not have a column mapping of their own.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 08, 2003 3:55 pm 
Newbie

Joined: Thu Dec 04, 2003 11:59 am
Posts: 11
Great! I will try now.
Thanks a lot.
George


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