Dear all,
I am a bit confused about the lazy loading mechanism.
My environnement is the following:
- JPA as API
- Hibernate as implementation with
hibernate-3.2.4.jar
hibernate-entitmanager-3.3.1.ga
hibernate-annotations-3.3.0.ga
My test is very simple.
1°) domain object model
Two domain objects Employee and Coordonnes, with an association One-to-One (unidiretional) between the two ones and coordonnees association configured to be lazy-loaded.
Below is an excerpt:
Code:
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class Employee implements Serializable {
...
@OneToOne(fetch=FetchType.LAZY)
private Coordonnees coordonnees;
}
2°) navigation:
Two screens, the first one to make a search on list of employees based on
search criteria and the seconf to display the results.
a) When i do the research, Hibernate runs well and loads a runtime proxy for the association entity coordonnees.
b) What i wonder is why Hiberate makes the whole SQL request on this proxy
even if the only property asked on this object in the jsf page is the identifier propertyIn the debugger, it's very clear that when the employee.coordonnees.getId() is called that Hibernate makes the proxy fully loaded by hinting the db.
Code:
<rich:column>
<f:facet name="header">
#{messages['employe.identifiant.header']}
</f:facet>
#{employe.coordonnees.id}
</rich:column>
here's the sql order generated by hibernate:
Code:
[24/09/08 17:43:16:187 CEST] 00000028 SystemOut O Hibernate:
/* load com.natixis.demosphinx.exemples.jpa.employe.metier.Coordonnees */ select
coordonnee0_.YCOIDN as YCOIDN0_0_,
coordonnee0_.LADRT1 as LADRT2_0_0_,
coordonnee0_.LCPITL as LCPITL0_0_,
coordonnee0_.COTLP1 as COTLP4_0_0_,
coordonnee0_.LVILTL as LVILTL0_0_
from
SPHINX_IDE_TEST_JPA_COORDONEES coordonnee0_
where
coordonnee0_.YCOIDN=?
I am just surpised that Hibernate needs to fully load the proxy when only it's identifier is called (because the proxy is alreeady supposed to hold this property). I thought it was only necessary when others properties were asked.
Did i miss something?
Thanks for your response,
Regards[/b]