-->
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.  [ 3 posts ] 
Author Message
 Post subject: query unidirectional one-to-many relationship
PostPosted: Tue Sep 20, 2005 4:00 pm 
Beginner
Beginner

Joined: Wed Mar 16, 2005 4:07 pm
Posts: 22
hi there,

i have a unidirectional one-to-many relationship "events" from a class user to a class event, i.e. a user has a set of events. but events don't know about user. it's unidirectional because the OO design has a clear dependency check and the event class really doesn't need to know about the user.

now if i want to query events with user information or have constraint based on user attribute, i think i can do this:

from user u, event e where e in elements(u.events) and u.name != 'blah'

since the relationship is unidirectional, i cannot do a more natural one like this: (if there were a bidirectional relationship from event to user as well)

from user u, event e where e.user = u and u.name != 'blah'

my question is the first query looks more expensive than the 2nd one because it's doing a "in", is that right? is there anyway to do something like the 2nd query while keeping the unidirectional relationship? (because i really hate to change the object model just for the sake of better query performance.)

thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 20, 2005 10:04 pm 
Senior
Senior

Joined: Wed Jul 13, 2005 4:31 pm
Posts: 142
Location: Seattle, WA
you can check the exact sql query executed by turning on sql output.

<property name="hibernate.show_sql">true</property>

That will tell you if the query is much more expensive.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 21, 2005 5:21 am 
Beginner
Beginner

Joined: Tue Sep 20, 2005 4:32 am
Posts: 29
Location: Cluj-Napoca
Try this:
from user u inner join u.events e where u.name != 'blah'


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