Hibernate version: 216
This question applies more to the design than implementation - hence no code is provided.
A very simple scenario:
I have an entity object called User.java which has 6 fields (consider all of them Strings for now - except the id field) :
- id
- name
- email
- phone
- dob
Which maps to a MySQL table called USER, and each field in the object instance maps to a column in the USER table.
My mapping document is also simple:
<hibernate-mapping package="ka">
....<class name="User" table="USER" proxy="User">
........<id name="id">
............<generator class="native"/>
........</id>
........<property name="name" />
........<property name="email"/>
........<property name="phone" />
........<property name="dob"/>
....</class>
</hibernate-mapping>
I can easily load/save/update the object to-and-from the USER table without any problems (of course!).
However, let's say I only want id, name and email fields to be loaded from the database when I run session.load(...). Imagine, that I have a large entity object with 120 fields each mapping to a column in a db table (that has 120 columns). In the "list" view of the items, I only want to show, say, 8 of the 120 fields - but if Hibernate does not provide a way to some how "Mask" the rest of the 112 fields, then everytime I will have to fetch all the 120 fields from the database - even if I only want 8 of them.
If, let's say, I remove one of the property declarations from the mapping document - for instance <property name="name" />, then Hibernate only loads the id, email, phone and dob. The value of "name" field remains null. But does Hibernate provide a dynamic masking or dynamic selection support for a persistence object whose fields and property mappings have already been statically defined??
We are currently using a Selective Query work-around for obtaining this feature (outside of Hibernate) - we create dynamic SQL strings based on the type of view selected by the user.
Gurus, please help.
Thanks.
Kartik
|