Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No exception of type DataAccessException can be thrown; an exception type must be a subclass of Throwable

My source code like below. It has a error, "No exception of type DataAccessException can be thrown; an exception type must be a subclass of Throwable".

I can't understand why the error ocurrs. let me know. thx.

package com.sds.afi.cosmos.cmm.db.impl;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import org.springframework.stereotype.Repository;

import com.sds.afi.cosmos.cmm.db.MainDao;

@Repository
//@SuppressWarnings("unchecked")   // 부적절한 컴파일러의 경고를 제거
public class MainDaoImpl extends SqlMapClientDaoSupport  implements MainDao {

    @Autowired
    private SqlMapClientTemplate sqlMapClientTemplate;

    @SuppressWarnings("unchecked")
    @Override
    public List<HashMap> getUserInfo() throws DataAccessException {

        List<HashMap> lists;

        lists = sqlMapClientTemplate.queryForList("common.getList");

        return lists;
    }

}
like image 909
verystrongjoe Avatar asked Apr 30 '12 06:04

verystrongjoe


People also ask

What is DataAccessException?

Class DataAccessExceptionThis exception hierarchy aims to let user code find and handle the kind of error encountered without knowing the details of the particular data access API in use (e.g. JDBC). Thus, it is possible to react to an optimistic locking failure without knowing that JDBC is being used.

Is an error is a subclass of exception?

An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch. Most such errors are abnormal conditions. The ThreadDeath error, though a "normal" condition, is also a subclass of Error because most applications should not try to catch it.

How does spring boot handle data access exception?

you need not handle any database-related exceptions explicitly instead spring jdbc framework will handle it for you. all the exceptions thrown by the spring jdbc framework are subclasses of dataaccessexception which is a type of runtimeexception, so you need not handle it explicitly.

Which of these is the root of the hierarchy of Spring data access exceptions?

Spring provides a convenient translation from technology-specific exceptions like SQLException to its own exception class hierarchy with the DataAccessException as the root exception.


2 Answers

This can happen if some class in the type-hierarchy of the exception is not on the class-path. In that case, its not possible to verify whether the exception really extends Throwable, whether it is a checked one or not, etc. Hence the errors. e.g superclass of Dataaccessexception : NestedRuntimeException may be missing from the class-path as it is in a differnt jar i.e. spring-core.

like image 70
manoj mokashi Avatar answered Sep 25 '22 22:09

manoj mokashi


Your DataAccessException is not a subclass of Throwable class (extends Throwable). It should be, and without this inheritance, your code is not compilable with the current throws clause.

Here is an example: http://www.osix.net/modules/article/?id=754

like image 35
Gergely Bacso Avatar answered Sep 26 '22 22:09

Gergely Bacso