1
我使用Tomcat 6.0,mybatis和Oracle XAPool開發應用程序。 當我運行應用程序時,會生成以下堆棧跟蹤。XA池中的ClassCastException
2012-05-10 16:19:16,328 ERROR [jatis.avantrade.foundation.model.dao.DAOHelper] [t] - datasource jndi : org.enhydra.jdbc.pool.StandardXAPoolDataSource
2012-05-10 16:19:16,328 ERROR [jatis.avantrade.foundation.model.dao.DAOHelper] [t] - org.enhydra.jdbc.pool.StandardXAPoolDataSource cannot be cast to org.enhydra.jdbc.pool.StandardXAPoolDataSource
java.lang.ClassCastException: org.enhydra.jdbc.pool.StandardXAPoolDataSource cannot be cast to org.enhydra.jdbc.pool.StandardXAPoolDataSource
at jatis.avantrade.foundation.model.dao.DAOHelper.getSession(DAOHelper.java:73)
下面是獲取數據庫會話時的DAOHelper代碼。當我打印 數據源時,它顯示的類型是StandardXAPoolDataSource
。 奇怪的現象是stacktrace節目org.enhydra.jdbc.pool.StandardXAPoolDataSource
無法投射到org.enhydra.jdbc.pool.StandardXAPoolDataSource
。
相同的類不能投射到自己?
protected SqlSession getSession() {SqlSession session = sessionLocal.get();
if (session == null) {
ConfigurationManager configurationManager = ConfigurationManagerSupport .getConfigurationManager(5000);
RootContextConfiguration contextConfiguration = (RootContextConfiguration) configurationManager
.getContextConfiguration(RootContextConfiguration.CONTEXT);
session = contextConfiguration.getMyBatisSession(MYBATIS_ID);
log.error("data source : "
+ session.getConfiguration().getEnvironment()
.getDataSource());
log.error("connection : " + session.getConnection());
sessionLocal.set(session);
log.error("factory : "
+ session.getConfiguration().getEnvironment()
.getTransactionFactory());
String DATASOURCE_CONTEXT = "java:comp/env/jdbc/avantrade";
Connection result = null;
try {
Context initialContext = new InitialContext();
DataSource datasource = (DataSource) initialContext
.lookup(DATASOURCE_CONTEXT);
log.error("datasource jndi : " + datasource);
log.error("datasource jndi : " + datasource.getClass().getName());
log.error("datasource jndi name : " + ((StandardXAPoolDataSource) datasource).getDataSourceName());
log.error("datasource jndi connection : " + ((StandardXAPoolDataSource) datasource).getConnection());
{
result = datasource.getConnection();
log.error("connection jndi : " + result);
log.error("connection jndi : " + result.getClass().getName());
}
} catch (NamingException ex) {
log.error(ex.getMessage(), ex);
} catch (SQLException ex) {
log.error(ex.getMessage(), ex);
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
}
}
return session;
}
謝謝。
謝謝。是工作。 :) –