[英]Could not get JDBC Connection / Transaction is not active
我正在努力通過 Spring Jdbc 調用我的數據庫,關於堆棧溢出的任何問題都不適合我,所以這就是我問它的原因。
這是我的 DAO
public class CruDao extends JdbcDaoSupport implements ICruDao{
private final Logger LOG = LoggerFactory.getLogger(CruDao.class);
@Override
public String obtainCode(String codiModel) {
String code = null;
SimpleJdbcCall funcio = new SimpleJdbcCall(getJdbcTemplate()).withFunctionName("funcCru");
MapSqlParameterSource parameter = new MapSqlParameterSource().addValue("id", codiModel);
try {
code = funcio.executeFunction(String.class, parameter);
LOG.debug("Generated Code: " + code);
}catch(Exception ex){
LOG.error("Error",ex);
}
return codiCRU;
}
}
這是調用executeFunction
行時拋出的異常:
org.springframework.dao.DataAccessResourceFailureException: Error retreiving database metadata; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Could not get Connection for extracting meta data; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.jboss.util.NestedSQLException: Transaction is not active: tx=TransactionImple < ac, BasicAction: -3f5796c1:d4ac:5e1c3647:9ff status: ActionStatus.ABORTED >; - nested throwable: (javax.resource.ResourceException: Transaction is not active: tx=TransactionImple < ac, BasicAction: -3f5796c1:d4ac:5e1c3647:9ff status: ActionStatus.ABORTED >)
編輯我調用我的 DAO 的方法已經是 @Transactional
@Override
@Transactional
public byte[] obtenirModel(String codiModel) {
byte[] genDocByteArray = null;
codiCRU = cruDao.obtainCode(codiModel);
if(codiCRU == null || codiCRU.length() < 1){
log.error("Errorrr");
return null;
}
...
我缺少什么? 謝謝指教。
訪問數據庫時,您需要有一個活動事務。 你已經在你的xml中定義了事務管理器bean,但沒有使用它。你需要注釋調用這個obtainCode
方法的服務方法@Transactional
。 另請注意,@ @Transactional
注釋方法需要公開並從另一個 bean 調用(由於代理機制),以使其正常工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.