Direct Field Access: Why does hibernate hit database when accessing key property?
posted 4 years ago
As always, when reading books and doing a net search does not help i always post my questions here. So, i would appreciate any help in this matter.
I would like to know why hibernate makes a database hit when we are accessing a key property on which direct field access has been enabled?
lets suppose I have Item with primary key as id field and description as an attribute.when i do this:
load method returns me a proxy. Item is not a fully initialized object yet. Hibernate has not fired a db hit in line 1 or line 2. when we do line 3, hibernate fires a db hit and fully initializes the Item object.
Now lets suppose i mark id field in Item hbm as access="direct". Taking the same example:
Hibernate does not fire a db hit in line 1. Hibernate will fire a db hit in line 2 as the id is marked as direct access.
Now why does hibernate fire a database hit when direct field access is enabled?