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.  [ 1 post ] 
Author Message
 Post subject: efficient information retrieval design
PostPosted: Fri Jul 06, 2007 1:23 pm 
Newbie

Joined: Thu Nov 02, 2006 1:15 pm
Posts: 3
I am using Hibernate 2, and won't be able to upgrade to 3 for a few months.

I have many Sites, each Site has many Users.
I have many Courses, each Site can be assigned to zero or more Courses. Within each Site, a Site administrator can assign zero or more of the Site's courses to each User.

When a Site administrator logs into the software, I want a list. Each entry in the list would contain a User and each Course (for that Site) that they are permitted to take.

Bad Option 1: Get a list of all Users for a Site. Iterate through the list, and for each user do Hibernate.initialize(user.getAssignedCourses());
I believe this is classic "n+1 selects" problem, and involves one query per User plus one query to get the user list.

Slightly Bad Option 2: Get a list of all Users joined with Courses for a site.
e.g. session.createQuery("select us, cu from CourseUser cu join cu.user us ...") That's only 2 queries to get all of the data - one for the list of Users and then one for the User and Course combination, but then I have many duplicate User objects in my List result. I also have to iterate through the entire list and transform the data into the format I want.

Slightly Bad Option 3: Get a list of all Users for the site, and a list of all Courses for the site. Generate an SQL query with many table joins that returns a result set with columns: user_id, has_course1, has_course2, has_course3, ... Then I get all of the data I want in the format I want, but it's not mapped to a Hibernate object so I have to take extra steps in my code to save changes back to the database.

I'm sure there's some simple piece of Hibernate functionality I'm missing that can breeze through this. Any suggestions?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.