-->
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: Using objects directly vs HQL Query
PostPosted: Mon Oct 18, 2004 3:49 am 
Beginner
Beginner

Joined: Tue Oct 05, 2004 5:15 am
Posts: 23
I'm having a bit of a problem coming up with an HQL query, and wondered if someone could help me....

In my domain model, I have a Topic, User and Subscription.
A Topic has a set of Subscriptions against it, and each Subscription belongs to a User. A User can have many simultaneous Subscriptions and additionally has the concept of a default Subscription.

So, a Topic has "Set getSubscriptions()", a Subscription has "User getUser" and additionally a User has "Subscription getDefaultSubscription".

Setting up the mappings and doing simple creats / finds has been fine.

However, I want to enforce a business rule that a Topic can not be deleted if it contains a default Subscription for a User with more than one subscription.
That is, a Topic containing a Subscription for which the following holds true:

Code:
user.getSubscription() == this && user.getSubscriptions().size() > 1;


Using my domain model its easy: Ask the Topic for its subscriptions, and for each Subscription - get the User, see if its the default subscription and if so see how many subscriptions it has.

The problem is, with a large number of subscriptions / Users, this could be very very inefficient.

So Im trying to come up with an HQL query to solve it more efficiently. I guess I want some sort of count query to find out for a given Topic whether it matches my criteria above.

It sounds quite tricky. Further, Im using MySql v4.0.x so I cant use subqueries.....
I've gone down a few avenues, but keep arriving at solutions that require subqueries.

Does anyone have any pointers that might help?
Or does it look like loading everything in (my first solution above) is the only way?

Thanks,

Dave


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 18, 2004 9:27 am 
Expert
Expert

Joined: Fri Feb 06, 2004 7:49 am
Posts: 255
Location: Moscow, Russia
MySQL 4.0 supports joins, and as I remember my DBA said me that it is possible to replace practically every query with use of subqueries by query with inner joins. So try to use INNER/LEFT JOIN and HAVING clause, don't forget to GROUP BY the columns from HAVING clause.

_________________
Leonid Shlyapnikov


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.