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