Forums Register Login

hibernate mapping and performance

+Pie Number of slices to send: Send
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 ??
+Pie Number of slices to send: Send
Lazy initialisation works for associated objects. If there is no association, then there can be no lazy loading.
+Pie Number of slices to send: Send
 

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"
..
}
+Pie Number of slices to send: Send
 


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?
Check your pockets for water buffalo. You might need to use this tiny ad until locate a water buffalo:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1321 times.
Similar Threads
Unique constraint on multiple columns (combined)
issues with hibernate lazy settings
Domain Object Vs DTO....
List query annotation ?
(Hibernate) lazy loading even when no association between classes ?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 04:37:28.