On Fri, May 22, 2009 at 8:18 AM, Miłosz Tylenda <[email protected]> wrote:

> That rings me on Tomcat clearing static variables [1] after reload, see
> org.apache.catalina.loader. WebappClassLoader.ENABLE_CLEAR_REFERENCES
> property. Maybe this explains something.
>

That does in fact change the behavior but only reinforces my suspicion that
after the redeploy, there are references to the static member from the first
start. Here are some print statements with ENABLE_CLEAR_REFERENCES=false:
*
(See note at bottom before wasting your time reading next block)*

FIRST START
Created new EM Factory
org.apache.openjpa.persistence.entitymanagerfactoryi...@3f7ede
Instantiated JpaDataSource com.sixdegreessoftware.sql.jpadatasou...@1a1cf5
JpaDataSource.getConnection()
com.sixdegreessoftware.sql.jpadatasou...@1a1cf5
dbRegistryMap = {default=com.sixdegreessoftware.sql.dbj...@e05748}
db = com.sixdegreessoftware.sql.dbj...@e05748

REDEPLOY

Created new EM Factory
org.apache.openjpa.persistence.entitymanagerfactoryi...@ca1676
Instantiated JpaDataSource com.sixdegreessoftware.sql.jpadatasou...@ee411c
JpaDataSource.getConnection()
com.sixdegreessoftware.sql.jpadatasou...@ee411c
dbRegistryMap = {default=com.sixdegreessoftware.sql.dbj...@e05748}
db = com.sixdegreessoftware.sql.dbj...@e05748

Note after redeploy the JpaDataSource instance has changed but dbRegistryMap
and db are the instances from the FIRST START. dbRegistryMap is the static
member coming up null when ENABLE_CLEAR_REFERENCES=true (the default). It
should be null, really, it's a member of a class that got reloaded and
should not be referenced anymore.

Maybe someone can try this with ENABLE_CLEAR_REFERENCES=true (the default).
If you have a Tomcat application with OpenJPA and a DataSource, subclass
your DataSource with this:

import java.io.PrintWriter;
import java.sql.*;
import java.sql.Connection;

import javax.sql.DataSource;

public class MyDataSource extends YourExistingDataSource {

    private static String testValue = "Shazaam!";

    public MyDataSource() {
        super();
        System.out.println("Instantiated MyDataSource " + this);
    }

    public Connection getConnection() throws SQLException {
        System.out.println("MyDataSource.getConnection() " + this + "
testValue " + testValue);
        return super.getConnection();
    }

}

Note that Shazaam! is printed in the first start phase but null after
redeploy.

*Hey WAAAAAIIIIIIIT a minute! *The class with the member coming up null is
in my webapp/WEB-INF/lib folder. openjpa.jar and geronimo.jar (et al) are in
catalina/lib. If I move openjpa jars to webapp/WEB-INF/lib the problem goes
away. DANG! Sorry to bother everyone.

-- 
Daryl Stultz
_____________________________________
6 Degrees Software and Consulting, Inc.
http://www.6degrees.com
mailto:[email protected]

Reply via email to