I think the problems comes from the cache implementation I use,
because It used to work quite well with jUnit tests and Default Cache
Implementation, and in this situation there is only One thread so
there wasn't any "dirty read" problem.

However, since I moved the application in Struts Actions Under tomcat,
I couldn't use the default Cache Implementation since it is not
thread-safe, and I got some errors with retrieved data. So, I thought
that using a thread-safe cache implementation such as
"ObjectCachePerBrokerImpl" could solve the problem, and by doing so I
solved the problems that used to happen, until I tried Crossreferenced
Objects...

I think that the source of the problem can be that I don't have any
global cache, because I retrieve first the Room Object and the nested
collection in a Struts Action (that might be running it it's own
thread), and then on the users collection elements I try to get
information on rooms, and it runs on a different thread from the first
Action since it located in a different Action.

So, I think that using a global cache which is thread-safe could solve
this issue, however there is only few documentation on caches
implementations in the cache package.

As I read in the javadoc, it seems that ObjectCachePerClassImpl is a
global cache, but i don't know if it thread-safe at all.

I retrieve Objects using this code :

public StorableObject get(Class objectClass, Integer pk) {
        PersistenceBroker broker = null;
        Object result;
        
        Criteria crit = new Criteria();
        crit.addEqualTo("pk",pk);
        crit = criteraModificator(objectClass, crit);

        
        try {
            broker = PersistenceBrokerFactory.defaultPersistenceBroker();
            QueryByCriteria query = new QueryByCriteria(objectClass, crit);
            result = broker.getObjectByQuery(query);
            
        } finally {
            if (broker != null)
                broker.close();
        }
        return (StorableObject)result;
    }


Regards,
Sylvain.

On Tue, 25 Jan 2005 11:23:02 +0100, Armin Waibel <[EMAIL PROTECTED]> wrote:
> Hi,
> 
> which version of OJB do you use?
> Did you try the default ObjectCache implementation? Same result?
> How does your code look like?
> 
> regards,
> Armin
> 
> Sylvain ~ wrote:
> > Hi,
> >
> > I'm trying to create crossreferenced objects, as specified in the
> > Cache documentation :
> >
> >  "It allows to perform circular lookups (as by crossreferenced
> > objects) that would result in non-terminating loops without such a
> > cache."
> >
> > I Use ObjectCachePerBrokerImpl since my application is multi-threaded
> > (and runs on tomcat)
> >
> > The problem is that I get a java.lang.StackOverflowError, when trying
> > to do so with theses classes (simplified for clarity). both classes
> > have auto-retrieve="true".
> >
> > Any Idea to make it work would be appreciated.
> > Sylvain.
> >
> > public class User {
> >
> >        /**
> >        * --- PK ---
> >        * @ojb.field   primarykey="true"
> >        *              autoincrement="ojb"
> >        */
> >     private Integer pk=null;
> >
> >     /**
> >      * user room
> >      * @ojb.reference
> >      *                foreignkey="pk"
> >      */
> >     private Room room;
> >
> >     }
> >
> > public class Room {
> >
> >     /**
> >        * --- PK ---
> >        * @ojb.field   primarykey="true"
> >        *                              autoincrement="ojb"
> >        */
> >     private Integer pk=null;
> >
> >     /**
> >      * Students in this room
> >      * @ojb.collection
> >      *                foreignkey="fk"
> >      *                element-class-ref="kdms.core.persistent.User"
> >      *                auto-update="true"
> >      *                auto-retrieve="true"
> >      *                auto-delete="false"
> >      */
> >     private Vector users;
> > }
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to