[InterMine Dev] How to instantiate an Item from its identifier?

Sam Hokin shokin at ncgr.org
Thu Feb 25 16:30:55 GMT 2016


On 02/25/2016 09:17 AM, Justin Clark-Casey wrote:
> Hi Sam.  I might have the wrong end of the stick here.  If I do, a bit more context for this code would be great.  However, when you
> add an Item to a collection (e.g. via Item.addToCollection(String name, Item item) then it is only the reference ID that is stored,
> not the Item object.
>
> If the Item has already been written to the objectstore then it should be available via ObjectStore.getObjectById(Integer id).
> Otherwise, I believe you have to keep your own map of the Items as you've been doing.

You got it, Justin, thanks! The Item in the collection had, in fact, already been written to the object store, but that's an 
important fact to keep in mind. ObjectStore.getObjectById(Integer id) is exactly what I'm looking for!

Cheers!
Sam



More information about the dev mailing list