*
The moose likes Object Relational Mapping and the fly likes hibernate mapping and performance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "hibernate mapping and performance" Watch "hibernate mapping and performance" New topic
Author

hibernate mapping and performance

Frank Hsieh
Greenhorn

Joined: Feb 07, 2008
Posts: 2
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 ??
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Lazy initialisation works for associated objects. If there is no association, then there can be no lazy loading.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Frank Hsieh
Greenhorn

Joined: Feb 07, 2008
Posts: 2
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

Joined: Apr 14, 2004
Posts: 10336


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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: hibernate mapping and performance
 
Similar Threads
Domain Object Vs DTO....
(Hibernate) lazy loading even when no association between classes ?
List query annotation ?
Unique constraint on multiple columns (combined)
issues with hibernate lazy settings