Populating 1 @Entity's (transient) fields with another @Entity?
Hello All,
We're using the DPL on BDB-JE and have some beans with parent child relationships. On the children, we have foreign keys pointing to the primary keys of the parents. Our objects need to be eagerly loaded so they can be sent out to remote clients via a web service. I found myself copying and pasting very similar code to populate the transient instances.
For example:
public class Dad{
...
@PrimaryKey
String id;
}
public class Child{
@PrimaryKey
String id;
@SecondaryKey(relate = Relationship.MANY_TO_ONE, relatedEntity = Dad.class)
String dadsId;
transient Dad dad;
}
It is my understanding that there's no way presently to populate Dad automatically. Is that correct? Is a feature of this nature planned for a near-future release? Out of curiosity, what was the motivation for not including such functionality?
If this problem hasn't been solved already, my team was going to create our own Eager Loading annotation. Every entity in our project has an associated DAO that implements a specific interface, which we use as a convenient means to access an existing PrimaryIndex.
The tentative design:
public class Child{
....
@TransientLink( fkfield="dadsId")//fkfield is optional...only needed if there are more than one secondary keys pointing to the same entity.
transient Dad dad;
}
Our tentative design:
<ul><li>Our dao layer would implement a method named something like populateTransients(Object entity)
</li>
<li>Calling method would loop through all @TransientLink declarations on entity.</li>
<li>for each field, it'd find the associated @SecondaryKey field and call a PrimaryIndex.get to lookup the object associated with the fk and assign it to the transient field.
</li>
</ul>
I had 2 questions:
<ol><li>(asked above already ) Has something like this already been implemented?</li>
<li>Is there some logical reason why this is a foolish errand?
</li>
</ol>
If you're interested in implementing something similar, I'd be happy to donate the code and help with implementation. It seems like it could be generalized relatively easily to work directly in the base BDB classes instead of my daos.
Thanks,
Steven
Harvard Childrens Hospital Informatics Program