• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

scenario

 
Vinnie Jenks
Ranch Hand
Posts: 207
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So...what happens when I'm using eclipse and I've got a one-to-many relationship defined in my hbm.xml file...and I'm creating a page with a form to edit some records. On my page I've got some dropdown menus that call some of these objects for which I'd only need the parent records in the dropdown...not all of the child records as well?

Do I dynamically load another hbm.xml for that class to get only the records I want w/o the overhead of the extra joined data?

What do I do w/ objects if I don't want *all* of those records and only need a flat set of data from one table!?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Configure your mapping to lazily load associated objects and don't call the getter for that property. The child records will not be initialized until you ask for them.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paul Sturrock:
Configure your mapping to lazily load associated objects and don't call the getter for that property. The child records will not be initialized until you ask for them.


True, but I think in his case for other "screens" that he has he wants eager loading, but for just that one screen he wants lazy loading.

Good question, even if that isn't what he is looking for.

Dropdowns, which I label as lookups, sometimes it is better to have a sql or hsql to get just the field information from the one table and put it into a Map or something to return to the client side.

We have screens like that and we created a Map that holds all the lookup values. So on one screen we might have 5 lookups, and on the serverside we query to get all 5 lookups, make a Map that has the "name" of the lookup as the key and a List of values as the value mapped to that key, then on the client side use a key, get the list and populate the dropdown. This keeps the calls to the serverside to one call and we get all 5 dropdown lists in the Map.

By the way Vinnie, it is good to see that you are now really liking Hibernate.

Mark
 
Vinnie Jenks
Ranch Hand
Posts: 207
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paul Sturrock:
Configure your mapping to lazily load associated objects and don't call the getter for that property. The child records will not be initialized until you ask for them.


Right, I understand this...but the problem is the query being executed against the database - it is still joining out and getting too much data for what I'm trying to achieve - performance is critical to me and this hinders performance quite a bit.
 
Vinnie Jenks
Ranch Hand
Posts: 207
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mark Spritzler:


True, but I think in his case for other "screens" that he has he wants eager loading, but for just that one screen he wants lazy loading.

Good question, even if that isn't what he is looking for.

Dropdowns, which I label as lookups, sometimes it is better to have a sql or hsql to get just the field information from the one table and put it into a Map or something to return to the client side.

We have screens like that and we created a Map that holds all the lookup values. So on one screen we might have 5 lookups, and on the serverside we query to get all 5 lookups, make a Map that has the "name" of the lookup as the key and a List of values as the value mapped to that key, then on the client side use a key, get the list and populate the dropdown. This keeps the calls to the serverside to one call and we get all 5 dropdown lists in the Map.

By the way Vinnie, it is good to see that you are now really liking Hibernate.

Mark


Hmm, I suppose that's one way to do it. It's looking like it will be very hard for me to avoid using HQL (I'd prefer to use Criteria queries purely.)

I was thinking of a way I could maybe load alternative hbm.xml files for the objects dynamically (simple factory) so that I could always have a simple config-per-table if I needed it for each of my objects.

I suppose it's possible but probably not performant.

And yeah, I like Hibernate a lot! I just had a lot of frustrations w/ Session context (and haven't honestly found an elegant solution to it yet) and lifecycle. I was really fed up after trying to get simple answers on the Hibernate forum.

You've been a big help Mark, thanks!
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Vinnie. I too am actually on the beginning side of the learning curve.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic