arvinder wrote: > > You can do this by having a many to many association between users and > groups as follows, assuming you have User, Group and Group_User tables, > where Group_User is a link table, you can avoid n+1 selects by having the > following mapping in User.hbm.xml > <set name="groups" outer-join="true" table="Group_User"> > <key column="user_id"/> > <many-to-many column="group_id" outer-join="true" class="Group"/> > </set> >
Cool, I will try it out. arvinder wrote: > > Note if you have outer-join="true" only as an attribute of the set element > it will eager fetch only the rows from the Group_User table and will > result in n+1 selects as you have described below, to get the groups. But > when you add outer-join="true" as an attribute in the many-to-many > element, it will fetch the group instances too by fetching rows from Group > table in the same query. > Ahhh, these little quirks that makes all the difference. Is there a good article, book, howto, paper, ... on this kinds of tricks. All the examples I find are a bit simple, mostly for getting started. I really good book on the subject would be great. (There is probably a jungle of not-so-great books out there.) arvinder wrote: > > Along with the above you need to set the hibernate property > hibernate.max_fetch_depth=2 (default is 1) as hibernate has to traverse > two levels to get the groups. > Which config? /WEB-INF/hibernate.properties? Will this effect other parts of my project (I'm guessing it will, but how...) arvinder wrote: > > Now the down side is that this outer join query will be run each time a > user instance is loaded. You might encounter performance problems if you > are not using scalar queries to get a list of users. > How do I know if I'm using scalar queries for lists? (Sorry, I'm new at this.) arvinder wrote: > > Hope this helps > Sure, thanks! -- View this message in context: http://www.nabble.com/Getting-the-architecture-right-tf4081789s2369.html#a11683721 Sent from the AppFuse - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
