-->
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.  [ 6 posts ] 
Author Message
 Post subject: dynamic sql
PostPosted: Thu Dec 07, 2006 5:38 pm 
Newbie

Joined: Thu Dec 07, 2006 1:02 pm
Posts: 10
I have a class:

[code]public class UserAll extends User {

private [b]Employer[/b] employer = null;
private [b]Collection[/b] roles = new LinkedList();
private [b]Collection [/b]groups = new LinkedList();

public UserAll() {
super();
}

public UserAll (long id) {
super(id);
}

/* setters / getters below */[/code]

I have a search screen which has the name, employers, groups and roles that we allow a user to search from. We then dynamically generate the sql, depending on what the user input, to return our UserAll objects.

We are running into a performance issue since Hibernate seems to be running a query for EVERY UserAll objects groups, roles and employers, etc, etc. We've tried using HQL but have had no luck with speeding up the performance.

Does anyone hear have any ideas as to speed this process up?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 08, 2006 5:11 am 
Regular
Regular

Joined: Wed Mar 23, 2005 8:43 am
Posts: 105
Location: Moscow, Russia
What was your mapping? Do you map your associations as Lazy? Do you use fetch join in HQL?

_________________
Best Regards


Top
 Profile  
 
 Post subject: Lazy mappings
PostPosted: Fri Dec 08, 2006 5:48 am 
Newbie

Joined: Fri Jul 15, 2005 12:42 am
Posts: 18
Two suggestions
1) Use lazy mappings for your collections if you don't require them in the result
2) If you require these collections Use left join fetch


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 08, 2006 10:20 am 
Newbie

Joined: Thu Dec 07, 2006 1:02 pm
Posts: 10
We're using HQL and we've tried a left outer join to get the Collection of groups. However we need 3 groups of Collections with our UserAll object. According to Hibernate, you can only attach one Collection to an object, which leaves us with an imcomplete object...

Any suggestions?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 08, 2006 11:24 am 
Newbie

Joined: Thu Dec 07, 2006 1:02 pm
Posts: 10
lester wrote:
What was your mapping? Do you map your associations as Lazy? Do you use fetch join in HQL?


Our mapping on the userAll object has a lazy fetch


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 08, 2006 11:33 am 
Newbie

Joined: Thu Dec 07, 2006 1:02 pm
Posts: 10
The thing is, we can have to switch lazy=false because we need that object to contain everything, except on this one screen. The screen I am referring to is a user search screen where they can search for a user by their last name, first name, a group they belong to or a role they belong to.

Depending on what the user enters we dynamically create the sql to pull back the information. We're wondering if we could pull all the Collection information into our UserAll object with one simple sql statement instead of Hibernate going to the database for every role, every group, etc, etc. One UserAll Object ends up having to make about 7 queries to populate it.

We've tried using HQL with outer joins and with fetch, however none of these solutions seems to work. It seems as though hibernate only allows us to fetch one Collection into an object at a time, which means hibernate still has to do many queries to populate that Object.

Anyways, I hope this is making sense... any help would be greatly appreciated


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