You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Steve Drake <st...@yahoo.com> on 2005/01/11 20:05:34 UTC

StackOverflowError exception

I'm using both the DAO and SQLMaps 2.x framework, JDK
1.4, Tomcat 5.0.18, MySQL 3.23.58, to develop a web
application. The problem I'm having is that, if I
don't attempt to access the database for several
hours, I get a java.lang.StackOverflowError exception
(see below) on the first request after that idle
period. Subsequent requests work fine - (for example,
if I simply reload the page that made the database
request). I'm not using a database pool (yet).  The
exception is thrown in the statement:
---
creds = (Credentials) queryForObject(map, hm);
---


I'm using a servlet to persist instances of different
services. For example,
---
public class SqlMapServlet extends HttpServlet {
 private static UserService userService;

 public void init() throws ServletException {
   try {
      userService = UserService.getInstance();
   } catch (Exception e) {
System.out.println(e.getMessage()); }
 }
}
---

A static userService object is instantiated from the
UserService class. The expectation is that this object
will not be garbage collected because the
SqlMapServlet has a handle to it. The UserService
class also authenticates a user login attempt:

---
public class UserService {

 private static final UserService instance = new
UserService();
                                                      
                        
 private DaoManager daoManager =
DaoConfig.getDaoManager();
                                                      
                        
 private UserDao userDao;

 public UserService() {
   userDao = (UserDao)
daoManager.getDao(UserDao.class);
 }
                                                      
                        
 public static UserService getInstance() {
   return instance;
 }

**
* Authenticate a user.
*/
 public User authenticate(String loginName, String
password) throws
  
InvalidLoginException,ExpiredPasswordException,AccountLockedException,
   DatastoreException {
   User userProfile = null;
                                                      
                        
// See if the login info passes muster.
   try {
     daoManager.startTransaction();
                                                      
                        
     Credentials creds =
userDao.getCredentials(loginName, password);
     if (creds != null)
       userProfile = userDao.getUser(loginName);
                                                      
                        
     daoManager.commitTransaction();
                                                      
                        
   } finally {
     daoManager.endTransaction();
   }
                                                      
                       
   return userProfile;
 }

}

The dao.xml file looks like:
---
<?xml version="1.0" encoding="UTF-8"?>
                                                      
                        
<!DOCTYPE daoConfig
   PUBLIC "-//iBATIS.com//DTD DAO Configuration
2.0//EN"
   "http://www.ibatis.com/dtd/dao-2.dtd">
                                                      
                        
<daoConfig>
                                                      
                        
 <context>
                                                      
                        
   <transactionManager type="SQLMAP">
     <property name="SqlMapConfigResource"
       value="config/SqlMapConfig.xml"/>
   </transactionManager>
                                                      
                        
   <dao interface="edu.orst.cgrb.dao.iface.UserDao"
       
implementation="edu.orst.cgrb.dao.sqlmap.UserSqlMapDao"
/>  
 </context>                                           
                                   
</daoConfig>
---

Finally, the UserSqlMapDao class contains a
getCredentials() method. The StackOverflow exception
that I'm seeing is thrown within this method at
queryForObject() (or a method that it invokes):
---
 public Credentials getCredentials(String loginName,
                                                    
String password) {
   String map = "authenticate";

   HashMap hm = new HashMap();
   hm.put("loginName", loginName);
   hm.put("password", password);
                                                      
                        
   Credentials creds = null;
   try {
     creds = (Credentials) queryForObject(map, hm);
   } catch (Exception e) {
     e.printStackTrace();
   }
                                                      
                        
   return creds;
 }
---

Oh, yeah. And SqlMapConfig.xml looks like:

---
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMapConfig
   PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"
   "http://www.ibatis.com/dtd/sql-map-config-2.dtd">
                                                      
                        
<sqlMapConfig>
                                                      
                        
 <properties resource="config/SqlMapConfig.properties"
/>
                                                      
                        
 <settings
   cacheModelsEnabled="true"
   enhancementEnabled="true"
   lazyLoadingEnabled="true"
   errorTracingEnabled="false"
   maxRequests="32"
   maxSessions="10"
   maxTransactions="5"
   useStatementNamespaces="false"/>
 <transactionManager type="JDBC" >
   <dataSource type="SIMPLE">
     <property name="JDBC.Driver" value="${driver}"/>
     <property name="JDBC.ConnectionURL"
value="${url}"/>
     <property name="JDBC.Username"
value="${username}"/>
     <property name="JDBC.Password"
value="${password}"/>
     <property name="JDBC.DefaultAutoCommit"
value="true" />

   </dataSource>
 </transactionManager>
 <sqlMap resource="config/User.xml" />
                                                      
                        
</sqlMapConfig>
---

Thanks for any ideas that you can provide. Following
is a screen copy of the StackOverflowException:

---


 HTTP Status 500 -

------------------------------------------------------------------------

*type* Exception report

*message*

*description* _The server encountered an internal
error () that prevented it from fulfilling this
request._

*exception*

javax.servlet.ServletException: Servlet execution
threw an exception

*root cause*

java.lang.StackOverflowError

*note* _The full stack trace of the root cause is
available in the Tomcat logs._

------------------------------------------------------------------------


     Apache Tomcat/5.0.18

---


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Re: StackOverflowError exception

Posted by Clinton Begin <cl...@gmail.com>.
We need a complete, full stack trace to help you figure this out.  We
can't work with that stripped down description.   As the message says,
you need to look in the tomcat logs to get the full trace.

Clinton


On Tue, 11 Jan 2005 11:05:34 -0800 (PST), Steve Drake
<st...@yahoo.com> wrote:
> I'm using both the DAO and SQLMaps 2.x framework, JDK
> 1.4, Tomcat 5.0.18, MySQL 3.23.58, to develop a web
> application. The problem I'm having is that, if I
> don't attempt to access the database for several
> hours, I get a java.lang.StackOverflowError exception
> (see below) on the first request after that idle
> period. Subsequent requests work fine - (for example,
> if I simply reload the page that made the database
> request). I'm not using a database pool (yet).  The
> exception is thrown in the statement:
> ---
> creds = (Credentials) queryForObject(map, hm);
> ---
> 
> I'm using a servlet to persist instances of different
> services. For example,
> ---
> public class SqlMapServlet extends HttpServlet {
>  private static UserService userService;
> 
>  public void init() throws ServletException {
>    try {
>       userService = UserService.getInstance();
>    } catch (Exception e) {
> System.out.println(e.getMessage()); }
>  }
> }
> ---
> 
> A static userService object is instantiated from the
> UserService class. The expectation is that this object
> will not be garbage collected because the
> SqlMapServlet has a handle to it. The UserService
> class also authenticates a user login attempt:
> 
> ---
> public class UserService {
> 
>  private static final UserService instance = new
> UserService();
> 
>  private DaoManager daoManager =
> DaoConfig.getDaoManager();
> 
>  private UserDao userDao;
> 
>  public UserService() {
>    userDao = (UserDao)
> daoManager.getDao(UserDao.class);
>  }
> 
>  public static UserService getInstance() {
>    return instance;
>  }
> 
> **
> * Authenticate a user.
> */
>  public User authenticate(String loginName, String
> password) throws
> 
> InvalidLoginException,ExpiredPasswordException,AccountLockedException,
>    DatastoreException {
>    User userProfile = null;
> 
> // See if the login info passes muster.
>    try {
>      daoManager.startTransaction();
> 
>      Credentials creds =
> userDao.getCredentials(loginName, password);
>      if (creds != null)
>        userProfile = userDao.getUser(loginName);
> 
>      daoManager.commitTransaction();
> 
>    } finally {
>      daoManager.endTransaction();
>    }
> 
>    return userProfile;
>  }
> 
> }
> 
> The dao.xml file looks like:
> ---
> <?xml version="1.0" encoding="UTF-8"?>
> 
> <!DOCTYPE daoConfig
>    PUBLIC "-//iBATIS.com//DTD DAO Configuration
> 2.0//EN"
>    "http://www.ibatis.com/dtd/dao-2.dtd">
> 
> <daoConfig>
> 
>  <context>
> 
>    <transactionManager type="SQLMAP">
>      <property name="SqlMapConfigResource"
>        value="config/SqlMapConfig.xml"/>
>    </transactionManager>
> 
>    <dao interface="edu.orst.cgrb.dao.iface.UserDao"
> 
> implementation="edu.orst.cgrb.dao.sqlmap.UserSqlMapDao"
> />
>  </context>
> 
> </daoConfig>
> ---
> 
> Finally, the UserSqlMapDao class contains a
> getCredentials() method. The StackOverflow exception
> that I'm seeing is thrown within this method at
> queryForObject() (or a method that it invokes):
> ---
>  public Credentials getCredentials(String loginName,
> 
> String password) {
>    String map = "authenticate";
> 
>    HashMap hm = new HashMap();
>    hm.put("loginName", loginName);
>    hm.put("password", password);
> 
>    Credentials creds = null;
>    try {
>      creds = (Credentials) queryForObject(map, hm);
>    } catch (Exception e) {
>      e.printStackTrace();
>    }
> 
>    return creds;
>  }
> ---
> 
> Oh, yeah. And SqlMapConfig.xml looks like:
> 
> ---
> <?xml version="1.0" encoding="UTF-8" ?>
> <!DOCTYPE sqlMapConfig
>    PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"
>    "http://www.ibatis.com/dtd/sql-map-config-2.dtd">
> 
> <sqlMapConfig>
> 
>  <properties resource="config/SqlMapConfig.properties"
> />
> 
>  <settings
>    cacheModelsEnabled="true"
>    enhancementEnabled="true"
>    lazyLoadingEnabled="true"
>    errorTracingEnabled="false"
>    maxRequests="32"
>    maxSessions="10"
>    maxTransactions="5"
>    useStatementNamespaces="false"/>
>  <transactionManager type="JDBC" >
>    <dataSource type="SIMPLE">
>      <property name="JDBC.Driver" value="${driver}"/>
>      <property name="JDBC.ConnectionURL"
> value="${url}"/>
>      <property name="JDBC.Username"
> value="${username}"/>
>      <property name="JDBC.Password"
> value="${password}"/>
>      <property name="JDBC.DefaultAutoCommit"
> value="true" />
> 
>    </dataSource>
>  </transactionManager>
>  <sqlMap resource="config/User.xml" />
> 
> </sqlMapConfig>
> ---
> 
> Thanks for any ideas that you can provide. Following
> is a screen copy of the StackOverflowException:
> 
> ---
> 
>  HTTP Status 500 -
> 
> ------------------------------------------------------------------------
> 
> *type* Exception report
> 
> *message*
> 
> *description* _The server encountered an internal
> error () that prevented it from fulfilling this
> request._
> 
> *exception*
> 
> javax.servlet.ServletException: Servlet execution
> threw an exception
> 
> *root cause*
> 
> java.lang.StackOverflowError
> 
> *note* _The full stack trace of the root cause is
> available in the Tomcat logs._
> 
> ------------------------------------------------------------------------
> 
>      Apache Tomcat/5.0.18
> 
> ---
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>

Re: StackOverflowError exception

Posted by Brandon Goodin <br...@gmail.com>.
SIMPLE datasource DOES pool connections. Here is a cut from the docs:

SimpleDataSourceFactory

The SimpleDataSource factory provides a basic implementation of a
pooling DataSource that is ideal for providing connections in cases
where there is no container provided DataSource. It is based on the
iBATIS SimpleDataSource connection pool implementation.

So perhaps you need to setup a pingQuery to validate that the
connection is still valid before using it.

See the sqlmaps user guide regarding <datasource> and SimpleDataSourceFactory.

Brandon

On Tue, 11 Jan 2005 11:05:34 -0800 (PST), Steve Drake
<st...@yahoo.com> wrote:
> I'm using both the DAO and SQLMaps 2.x framework, JDK
> 1.4, Tomcat 5.0.18, MySQL 3.23.58, to develop a web
> application. The problem I'm having is that, if I
> don't attempt to access the database for several
> hours, I get a java.lang.StackOverflowError exception
> (see below) on the first request after that idle
> period. Subsequent requests work fine - (for example,
> if I simply reload the page that made the database
> request). I'm not using a database pool (yet).  The
> exception is thrown in the statement:
> ---
> creds = (Credentials) queryForObject(map, hm);
> ---
> 
> I'm using a servlet to persist instances of different
> services. For example,
> ---
> public class SqlMapServlet extends HttpServlet {
>  private static UserService userService;
> 
>  public void init() throws ServletException {
>    try {
>       userService = UserService.getInstance();
>    } catch (Exception e) {
> System.out.println(e.getMessage()); }
>  }
> }
> ---
> 
> A static userService object is instantiated from the
> UserService class. The expectation is that this object
> will not be garbage collected because the
> SqlMapServlet has a handle to it. The UserService
> class also authenticates a user login attempt:
> 
> ---
> public class UserService {
> 
>  private static final UserService instance = new
> UserService();
> 
>  private DaoManager daoManager =
> DaoConfig.getDaoManager();
> 
>  private UserDao userDao;
> 
>  public UserService() {
>    userDao = (UserDao)
> daoManager.getDao(UserDao.class);
>  }
> 
>  public static UserService getInstance() {
>    return instance;
>  }
> 
> **
> * Authenticate a user.
> */
>  public User authenticate(String loginName, String
> password) throws
> 
> InvalidLoginException,ExpiredPasswordException,AccountLockedException,
>    DatastoreException {
>    User userProfile = null;
> 
> // See if the login info passes muster.
>    try {
>      daoManager.startTransaction();
> 
>      Credentials creds =
> userDao.getCredentials(loginName, password);
>      if (creds != null)
>        userProfile = userDao.getUser(loginName);
> 
>      daoManager.commitTransaction();
> 
>    } finally {
>      daoManager.endTransaction();
>    }
> 
>    return userProfile;
>  }
> 
> }
> 
> The dao.xml file looks like:
> ---
> <?xml version="1.0" encoding="UTF-8"?>
> 
> <!DOCTYPE daoConfig
>    PUBLIC "-//iBATIS.com//DTD DAO Configuration
> 2.0//EN"
>    "http://www.ibatis.com/dtd/dao-2.dtd">
> 
> <daoConfig>
> 
>  <context>
> 
>    <transactionManager type="SQLMAP">
>      <property name="SqlMapConfigResource"
>        value="config/SqlMapConfig.xml"/>
>    </transactionManager>
> 
>    <dao interface="edu.orst.cgrb.dao.iface.UserDao"
> 
> implementation="edu.orst.cgrb.dao.sqlmap.UserSqlMapDao"
> />
>  </context>
> 
> </daoConfig>
> ---
> 
> Finally, the UserSqlMapDao class contains a
> getCredentials() method. The StackOverflow exception
> that I'm seeing is thrown within this method at
> queryForObject() (or a method that it invokes):
> ---
>  public Credentials getCredentials(String loginName,
> 
> String password) {
>    String map = "authenticate";
> 
>    HashMap hm = new HashMap();
>    hm.put("loginName", loginName);
>    hm.put("password", password);
> 
>    Credentials creds = null;
>    try {
>      creds = (Credentials) queryForObject(map, hm);
>    } catch (Exception e) {
>      e.printStackTrace();
>    }
> 
>    return creds;
>  }
> ---
> 
> Oh, yeah. And SqlMapConfig.xml looks like:
> 
> ---
> <?xml version="1.0" encoding="UTF-8" ?>
> <!DOCTYPE sqlMapConfig
>    PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"
>    "http://www.ibatis.com/dtd/sql-map-config-2.dtd">
> 
> <sqlMapConfig>
> 
>  <properties resource="config/SqlMapConfig.properties"
> />
> 
>  <settings
>    cacheModelsEnabled="true"
>    enhancementEnabled="true"
>    lazyLoadingEnabled="true"
>    errorTracingEnabled="false"
>    maxRequests="32"
>    maxSessions="10"
>    maxTransactions="5"
>    useStatementNamespaces="false"/>
>  <transactionManager type="JDBC" >
>    <dataSource type="SIMPLE">
>      <property name="JDBC.Driver" value="${driver}"/>
>      <property name="JDBC.ConnectionURL"
> value="${url}"/>
>      <property name="JDBC.Username"
> value="${username}"/>
>      <property name="JDBC.Password"
> value="${password}"/>
>      <property name="JDBC.DefaultAutoCommit"
> value="true" />
> 
>    </dataSource>
>  </transactionManager>
>  <sqlMap resource="config/User.xml" />
> 
> </sqlMapConfig>
> ---
> 
> Thanks for any ideas that you can provide. Following
> is a screen copy of the StackOverflowException:
> 
> ---
> 
>  HTTP Status 500 -
> 
> ------------------------------------------------------------------------
> 
> *type* Exception report
> 
> *message*
> 
> *description* _The server encountered an internal
> error () that prevented it from fulfilling this
> request._
> 
> *exception*
> 
> javax.servlet.ServletException: Servlet execution
> threw an exception
> 
> *root cause*
> 
> java.lang.StackOverflowError
> 
> *note* _The full stack trace of the root cause is
> available in the Tomcat logs._
> 
> ------------------------------------------------------------------------
> 
>      Apache Tomcat/5.0.18
> 
> ---
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>