I have a web application deployed in a Tomcat 5.5 container. I use a SessionEventListener
bean that logs some activities in the database. Sometimes I get this error message:
java.sql.SQLException: StandardXAConnectionHandle:prepareStatement should not be used outside an EJBServer
at org.enhydra.jdbc.standard.StandardXAConnectionHandle.prepareStatement(StandardXAConnectionHandle.java:310)
at org.enhydra.jd开发者_Python百科bc.standard.StandardXAConnectionHandle.prepareStatement(StandardXAConnectionHandle.java:255)
at org.springframework.jdbc.core.PreparedStatementCreatorFactory$PreparedStatementCreatorImpl.createPreparedStatement(PreparedStatementCreatorFactory.java:233)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:532)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:739)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:762)
at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.update(NamedParameterJdbcTemplate.java:213)
at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.update(NamedParameterJdbcTemplate.java:217)
at hu.rate.session.RateDBSessionRegistry$4.doInTransactionWithoutResult(RateDBSessionRegistry.java:124)
at org.springframework.transaction.support.TransactionCallbackWithoutResult.doInTransaction(TransactionCallbackWithoutResult.java:33)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:127)
at hu.rate.session.RateDBSessionRegistry.refreshLastRequest(RateDBSessionRegistry.java:120)
The code that fails is the following:
txTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
public void doInTransactionWithoutResult(
TransactionStatus paramTransactionStatus) {
if(template.update(us, paramMap) == 0) {
logger.warn("No session in registry to be refreshed, sessionId = " + sessionId);
}
}
});
public void setTxManager(PlatformTransactionManager txManager) {
txTemplate = new TransactionTemplate(txManager);
}
My Spring bean config looks like this:
<bean id="jotm" class="org.springframework.transaction.jta.JotmFactoryBean" />
<bean id="txManager"
class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="userTransaction">
<ref local="jotm" />
</property>
</bean>
I do not really understand this issue, can you explain me what is wrong and how to fix it?
According to this page I found it looks like it is caused by an underlying NullPointerException. Also interestingly enough, there is a comment in that code right below it on if you want to use PreparedStatements you need to comment out two lines and uncomment two other lines. Might be worth looking into.
精彩评论