Hi,
I just need a couple of suggestions on what I'm doing to achieve the following.
In order to select only a specified set of fields from some table mapped against a persistent class,say A, one can execute the following simple HQL
select A.f1,A.f2 ...from A where [i]some filter condition.[/i]
The returned result will be a list of Object[]s.
But let's say I have a class structure as follows
class A {
int id;
int i2;
int i3;
B b;
}
class B {
String id;
String f2;
String f3;
}
Now,if I intend to obtain instances of A with only i2 and i3 populated
and only f2 and f3 of the corresponding B instances populated, then simply executing the following query
select a.i1,a.i2,a.b.f2,a.b.f3 from A a where ...
won't help.
The returned list of Object[] needs to be programmatically
re-organised into a set of sparsely populated (Meaning only specific fields populated)A objects.
My Approach :
In order to achieve the desired objective , I have used something called as Dynamic Mapping Management. To elaborate, I've dynamically created the DOMs of the mapping XMLs corresponding to A and B classes and modified the same programatically based on the business requirements.
Finally I created a single consolidated DOM object populated with only specific <property> elements ,as required.
So I come up with a DOM representation of something like the following at runtime.
<class name="A" table="A" lazy="true" proxy="WSItem">
<id name="id"
<generator class="native"/>
</id>
<property name="i2" column="ITEMNUMBER"/>
<property name="i3" column="ITEMTYPE"/>
<one-to-one name="B" />
</class>
<class name="B" table="B" lazy="true" proxy="WSItem">
<id name="id"
<generator class="native"/>
</id>
<property name="f2" column="xyz"/>
<property name="f3" column="abc"/>
</class>
I pass the new DOM to the configuration object and process the HQL below
from A where .....
The returned list is that of A objects (NOT Object[]s), with only specific fields of A and corresponding B objects populated.
Advantage : I'm spared the additional task of programmatic re-organisation of the list of Object[]s into a set of A objects
Please advise, if there's a better approach to achieve the same .
Thanks,
Santosh
|