users@glassfish.java.net

Re: Desparately need help with JPA (Toplink) cache problems

From: <glassfish_at_javadesktop.org>
Date: Thu, 24 Jul 2008 12:44:54 PDT

The references are being cleared correctly. I dump out the references to make sure (see the lines with XXX in them). Also here is the code that is doing the work:

    /** Add a new ConfigurationSet to this Hardwre. This determines if
     * there are too many configurations and if so, removes the oldest configurations.
     * @param cs The ConfigurationSet to add
     */
    public void addConfigurationSet(ConfigurationSet cs) {
        // Wire up this configuration set
        cs.setConfigurableHardware(this);
        this.configurations.add(cs);
        // Check to see if we need to remove a configuration set
        while (this.configurations.size() > MAX_OLD_CONFIGURATIONS) {
            ConfigurationSet ocs = getOldestConfigurationSet();
            this.configurations.remove(ocs);
            EntityManagerFactoryFacade.getEntityManager().remove(ocs);
        }
    }

There is actually a couple of base classes involved: ConfigurableHardware (which Chassis9145 ultimately is derived from) and ConfigurationSet (which ConfigurationSet9145 is ultimately derived from). When a ConfigurationSet is added to ConfigurableHardware, it comes into this method. The method adds the ConfigurationSet to the collection that ConfigurableHardware maintains and sets the ConfigurableHardware of the ConfigurationSet to "this" ConfigurableHardware.

When the maximum ConfigurationSets are reached, the oldest ConfigurationSet is located and then removed. The ConfigurationSet is removed from the ConfigurableHardware collection and then the EntityManager.remove is called on the ConfigurationSet.

The EntityManagerFactoryFacade is just a class that I wrote that allows me to return a wrapped EntityManager instance.

So I believe I am removing the relationships correctly. If there is something wrong, it is right here as there is no other code that can alter the collection or set the ConfigurableHardware for the ConfigurationSet.

An interesting note. Just on a whim, I removed the @Version attribute on the MappedSuperclass that all of these derive from so basically I removed the OptimisticLocking mechanism. I no longer observe the same behavior. Could something be wrong with the OptimisticLocking?

I appreciate the time taken to look at this and ggive me some pointers.

Brett
[Message sent by forum member 'bbergquist' (bbergquist)]

http://forums.java.net/jive/thread.jspa?messageID=289164