• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

hibernate mapping and performance

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hibernate 3 uses lazy loading. But, is it true that lazy load is mainly used when our POJO are like

Class A {
B b;
}

Class B {
..
}

i.e, POJO B is a class variable of POJO A, and meanwhile A and B map to two tables respectively ?

2. Without such class variable relation between the two POJOs, i.e. if we have several POJOs and each of them maps to a table, but none of them is a class variable of another POJO, then do we still need lazy load ??
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lazy initialisation works for associated objects. If there is no association, then there can be no lazy loading.
 
Frank Hsieh
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Paul Sturrock:
Lazy initialisation works for associated objects. If there is no association, then there can be no lazy loading.



Thank you. Couple more further questions

I) suppose we have

class A {

B b;
..
}

class B {..}

A includes a B b; if we do NOT use lazy load, people talked about it may load the "entire database' (scary.) So for this case, does it may load the entire table of "B" or "A" ?

II) Sometimes the two tables have association (one holds a foreign key to the other). But since the key is not a surrogate key, in POJO classes we may just treat the FK attribute as a regular variable. If that's the case, do we need to use lazy load ?

for example

class A {

int class_B_id; // instead of using "B b;"
..
}

class B {
int id; // maps to the "class_B_id"
..
}
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


A includes a B b; if we do NOT use lazy load, people talked about it may load the "entire database' (scary.) So for this case, does it may load the entire table of "B" or "A" ?


If you have an association between a table A and a table B that is not defined to use lazy initialization then when you load a record from A, you also load the corresponding related record(s) from B.


Sometimes the two tables have association (one holds a foreign key to the other). But since the key is not a surrogate key, in POJO classes we may just treat the FK attribute as a regular variable. If that's the case, do we need to use lazy load ?


Whether or not a foreign key is a surrogate key doesn't matter. You can treat the FK as a property rather than an associated object if you wish. I'm not sure what the advantage is though?
 
this is supposed to be a surprise, but it smells like a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic