-->
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.  [ 4 posts ] 
Author Message
 Post subject: Query unidirectional associations
PostPosted: Sun Nov 21, 2004 8:15 am 
Newbie

Joined: Sun Nov 21, 2004 8:02 am
Posts: 1
Hi Community,
I'm testing hibernate as an replacement for our current selfmade persistence OR-mechanismn. For now, most works great but the devil is in the details.

The (web-)applications we build depend heaviliy on existing components (user/security-management, forum etc.). These objects are packaged in a reusable application-independent jar-file (e.g. a standard User-POJO with its corresponding user.hbm-mapping, see mapping).

Here is my question:

Having this (definitly not editable) user-mapping-file in the jar we can only specify unidirectional associations between the user-object and concrete application objects. For example in an CMS-application a user can publish articles (User:Article = 1:N). An article is associated with an user via a many-to-one association. The User object doesn't know anything about the existence of article-objects.


Mapping documents:

User (sitting in external jar):
<class name="User" table="t_user">
<id name="ID" column="a_id" type="java.lang.Long"><generator
class="native" /></id>
<property name="Login" column="a_login" type="java.lang.String" length="255"/>
<property name="Pwd" column="a_pwd" type="java.lang.String" length="255"/></class>
</hibernate-mapping>

Article (application):
<class name="Article" table="t_article">
<id name="ID" column="a_id" type="java.lang.Long"><generator class="native"/></id>
<property name="Text" column="a_text" type="text"/>
<property name="Words" column="a_words" type="int"/>
<!-- association with user -->
<many-to-one name="Editor" class="User" column="a_userid" not-null="true"/>
</class>


Having this design, is it possible to query (criteria-api would be great, but hsql is no show stopper also) user objects for concrete features like the following one: Give me all users that have written articles containing e.g. more than words? Is this possible with one query/criteria or do we have to select all articles first and then loop over the result and collect the user?

Regards

Paul


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 21, 2004 10:12 am 
Regular
Regular

Joined: Tue Jan 27, 2004 12:22 pm
Posts: 103
Paul,
First of all: don't use capital startling letter for your attributes, it's bad desgin.
Answer to your question:
The following query probably works:
Code:
Select a.Editor from Article a
where words=:word


Please read the documentation. It's all explained there. See chapter 11 for the HQL features.

Greetz[/code]

_________________
Dencel
- The sun has never seen a shadow -


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 01, 2005 3:36 pm 
Newbie

Joined: Wed Sep 29, 2004 10:45 am
Posts: 6
Is it possible to use the Criteria API to make the same query?

Thanks,
zeng


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 01, 2005 5:45 pm 
Regular
Regular

Joined: Tue Jan 27, 2004 12:22 pm
Posts: 103
The Criteria query api is limited. Aggregated functions are not supported(yet). Look at Chapter 12 for the currently supported options. Hope this helps.

_________________
Dencel
- The sun has never seen a shadow -


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