oftentimes I have this kind of usage scenario:
entity A is connected to B through a 1–1 relation,
in code, I often simply use A.* and A.getB().getId(), I never use any other properties of B(),
since the Id of B is actually stored in table A already, I do not necessarily have to load the
B table, but hibernate always creates a JOIN or latter SELECT when it sees getB().
this is a huge problem if B table is big, or it has its own associations
is there a way to optimize for this special use case?
Thanks
Yang
Hibernate one-to-one: getId() without fetching entire object
http://javaprogrammingtips4u.blogspot.com/2010/04/field-versus-property-access-in.html
basically you need to put the annotation on getId() instead of private Integer Id.
in terms of xml mapping file, you just need to put access=”property” in the tag of your class