most efficient reference lookup for business objects?

Discussion in 'Java' started by Timasmith, Nov 6, 2006.

  1. Timasmith

    Timasmith Guest

    Hi,

    I have database tables which translate into business objects with 20-30
    fields, 5-10 child objects with again 20-30 fields.

    50% of the fields are a long integer relatiing to a reference table.
    In the object I have a display field which equates to the reference
    table display.

    Every time I pull an object out of the database I populate its
    reference displays, making it very easy to present searches, populate
    combo lists etc.

    However there is a cost to populating the object with all the 150+
    display values. If I am pulling out 50-100 objects from search
    results, that is a lot of lookups.

    Since I'm stubborn I refuse to entertain passing this workload on to
    the database. I dont care how efficient their caching is - that is not
    going to scale very well and it would be too complex to figure out
    clustering on the database side as I am supporting at least one open
    source database.

    As an FYI this is running on JBoss under a stateless session bean, I do
    use Hibernate for the data layer.

    So what I did was I have a local stateless session bean which performs
    the 'reference lookup'. Every time it does it, it pops the display and
    the id into a hashtable for next time. In fact in some cases it pops
    an entire business object into the hash.

    I wondered if the old Hashtable was really the right thing for this.
    It works, though obviously there is a danger that the cache would need
    purging to remain efficient and not hog too much memory. While I have
    a first pass at synchronizing the code, it probably needs more work to
    be more efficient.

    I also do this on the client - where it really helps as the client does
    not ask for business objects in the first place if they are cached
    locally. Of course when the client restarts that is lost.

    I considered caching the reference locally on the client. Obviously a
    lot of extra work to prevent stale data.

    Any other ideas on how to improve this?

    thanks
     
    Timasmith, Nov 6, 2006
    #1
    1. Advertising

  2. Timasmith

    Daniel Pitts Guest

    Timasmith wrote:
    > Hi,
    >
    > I have database tables which translate into business objects with 20-30
    > fields, 5-10 child objects with again 20-30 fields.
    >
    > 50% of the fields are a long integer relatiing to a reference table.
    > In the object I have a display field which equates to the reference
    > table display.
    >
    > Every time I pull an object out of the database I populate its
    > reference displays, making it very easy to present searches, populate
    > combo lists etc.
    >
    > However there is a cost to populating the object with all the 150+
    > display values. If I am pulling out 50-100 objects from search
    > results, that is a lot of lookups.
    >
    > Since I'm stubborn I refuse to entertain passing this workload on to
    > the database. I dont care how efficient their caching is - that is not
    > going to scale very well and it would be too complex to figure out
    > clustering on the database side as I am supporting at least one open
    > source database.
    >
    > As an FYI this is running on JBoss under a stateless session bean, I do
    > use Hibernate for the data layer.
    >
    > So what I did was I have a local stateless session bean which performs
    > the 'reference lookup'. Every time it does it, it pops the display and
    > the id into a hashtable for next time. In fact in some cases it pops
    > an entire business object into the hash.
    >
    > I wondered if the old Hashtable was really the right thing for this.
    > It works, though obviously there is a danger that the cache would need
    > purging to remain efficient and not hog too much memory. While I have
    > a first pass at synchronizing the code, it probably needs more work to
    > be more efficient.
    >
    > I also do this on the client - where it really helps as the client does
    > not ask for business objects in the first place if they are cached
    > locally. Of course when the client restarts that is lost.
    >
    > I considered caching the reference locally on the client. Obviously a
    > lot of extra work to prevent stale data.
    >
    > Any other ideas on how to improve this?
    >
    > thanks


    There are built in caching mechanisms for Hibernate, I wouldn't try to
    invent your own.
    If you don't need all of the data all of the time, you might try using
    lazy-loading.
     
    Daniel Pitts, Nov 6, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris S.

    Efficient String Lookup?

    Chris S., Oct 16, 2004, in forum: Python
    Replies:
    21
    Views:
    4,227
    Win Carus
    Oct 18, 2004
  2. David Pratt

    Efficient lookup in list of dictionaries

    David Pratt, Dec 5, 2005, in forum: Python
    Replies:
    2
    Views:
    301
    bruno at modulix
    Dec 5, 2005
  3. Ken Fine
    Replies:
    3
    Views:
    540
    Steven Cheng [MSFT]
    Jul 23, 2008
  4. Per Freem
    Replies:
    13
    Views:
    637
    Tim Chase
    Jan 13, 2009
  5. James
    Replies:
    30
    Views:
    1,143
    Chris M. Thomasson
    Nov 23, 2009
Loading...

Share This Page