-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Getting a sparsely populated object using Hibernate
PostPosted: Mon Mar 29, 2004 7:32 am 
Newbie

Joined: Mon Mar 22, 2004 5:23 am
Posts: 18
Location: Bangalore
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.