Unique persistent object and caching issue

From: Laurent Marchal (lmarcha..maeur.com)
Date: Tue Jul 15 2008 - 08:25:33 EDT

  • Next message: Andrus Adamchik: "Re: Unique persistent object and caching issue"

    Hi all,

        I have a problem that i cannot solve. My customer has a strange
    database schema : each table has a related "AUX" table where extended
    properties are stored in rows. For example

      .----------------------.
      | Artist |
      +----+-----------------+
      | Id | Name |
      +----+-----------------+
      | 1 | John Smith |
      '----+-----------------'

      .----------------------------------.
      | Artist_AUX |
      +----+-----------------+-----------+
      | Id | Name | Value |
      +----+-----------------+-----------+
      | 1 | DateOfBirth | 18/02/70 |
      | 1 | Gender | Male |
      | 1 | NickName | JSmith |
      '----+-----------------+-----------'

    It was a solution for my customer to store a lot of extended properties
    for Artist without adding/removing columns in the Artist table...

    To deal with this, i do not want to make a SQL request each time the
    user want to set/get an AUX property.
    So i created an AuxManager which basically fetch all aux rows in the AUX
    table the first time the user want to get/set a value in the AUX.
    This way only one request is made to fetch all extended properties.

    A simplified Artist class looks like :

        class Artist {
           //extended properties list
           private list<Artist_AUX> _auxList;

           public getDateOfBirth() {
                if (_auxList == null) {
                       _auxList = Artist.fetchAllArtistAux();
                 }
                 return _auxList.get("DateOfBirth");
            }
        }

        The getDateOfBirth() is an extended property, so if the aux row list
    is null, I fetch all the Artist_AUX rows in one time and then do the stuff.

        My problem is : since cayenne has only 1 instance of each unique
    persistent object, the persistent Artist object is not re-created for
    each query, so the internal "list<Artist_AUX> _auxList" is not reseted
    to null, and the extended properties are not refreshed.

    How can i force this list to be refreshed when a fresh Artist object is
    fetched ? Or is there another way to do that ?

    Thanks.
    Laurent Marchal.



    This archive was generated by hypermail 2.0.0 : Tue Jul 15 2008 - 08:26:27 EDT