[Contrib: Evaluation System] From EID to ID without getting object

Jim Eng jimeng at umich.edu
Tue Jul 13 18:30:36 PDT 2010


This is a long email with a fairly specific question at the end.  Along the way, it describes the context of the question, which is about streamlining the behavior of sakai's hibernate implementation and specifically the generic DAO.  The question is whether we can somehow provide a reference to an existing object from another table without creating that other object.  Here's the detail:

In our eval import code, we are unmarshalling XML describing an object of type EvalTemplateItem using XStream. That creates the java object and initializes most of its member variables. One of the member variables (named "item") is an object of type EvalItem, which already exists in the system. The XML will refer to the item like this:

      <item>
        <eid>1</eid>
      </item>

That indicates that this EvalTemplateItem contains a reference to the EvalItem whose EID is "1".  In the database, the column for the "item" property in the EVAL_TEMPLATE_ITEM table will be the foreign key containing the ID of the EvalItem with EID of "1".  To make that happen, we are retrieving the EvalItem object as follows:

	EvalItem item = this.authoringService.getItemByEid(itemEid);

Then we replace the bare-bones value of the EvalTemplateItem's "item" member variable with that value: 

	newTemplateItem.setItem(item);

Then after some additional fix-up, we save the new EvalTemplateItem, which saves the ID of the EvalItem into the "item" column for the EvalTemplateItem.

The problem is that we are spending lots of time retrieving those objects of type EvalItem just to get the ID and save the reference to it in the right place.  We are working through sakai's implementation of hibernate and Aaaron's version of the generic dao.  The code I've described above ends up spending way too much time in calls to authoringService.getItemByEid(itemEid), which ends up running SQL similar to this:

	select this_.ID as ID126_1_, this_.EID as EID126_1_, this_.LAST_MODIFIED as LAST3_126_1_, this_.OWNER as OWNER126_1_, this_.ITEM_TEXT as ITEM5_126_1_, this_.DESCRIPTION as DESCRIPT6_126_1_, this_.SHARING as SHARING126_1_, this_.CLASSIFICATION as CLASSIFI8_126_1_, this_.EXPERT as EXPERT126_1_, this_.EXPERT_DESCRIPTION as EXPERT10_126_1_, this_.SCALE_FK as SCALE11_126_1_, this_.USES_NA as USES12_126_1_, this_.USES_COMMENT as USES13_126_1_, this_.DISPLAY_ROWS as DISPLAY14_126_1_, this_.SCALE_DISPLAY_SETTING as SCALE15_126_1_, this_.CATEGORY as CATEGORY126_1_, this_.LOCKED as LOCKED126_1_, this_.COPY_OF as COPY18_126_1_, this_.HIDDEN as HIDDEN126_1_, this_.AUTO_USE_TAG as AUTO20_126_1_, evalscale2_.ID as ID131_0_, evalscale2_.EID as EID131_0_, evalscale2_.LAST_MODIFIED as LAST3_131_0_, evalscale2_.OWNER as OWNER131_0_, evalscale2_.TITLE as TITLE131_0_, evalscale2_.SCALE_MODE as SCALE6_131_0_, evalscale2_.SHARING as SHARING131_0_, evalscale2_.EXPERT as EXPERT131_0_, evalscale2_.EXPERT_DESCRIPTION as EXPERT9_131_0_, evalscale2_.IDEAL as IDEAL131_0_, evalscale2_.LOCKED as LOCKED131_0_, evalscale2_.COPY_OF as COPY12_131_0_, evalscale2_.HIDDEN as HIDDEN131_0_ from EVAL_ITEM this_ left outer join EVAL_SCALE evalscale2_ on this_.SCALE_FK=evalscale2_.ID where (this_.EID=?)

I'm wondering if there's a way to get hibernate to short-cut that without having to rewrite all the business logic and persistence code.  Can we ask the DAO for a reference to the EvalItem without actually retrieving it and insert that reference into the EvalTemplateItem so it will be saved as a reference to the EvalItem?  

Thanks.

Jim

    

	


More information about the evaluation mailing list