Spring で宣言型トランザクションを使用しています。「トランザクション」で注釈が付けられたサービスレイヤーがあります。このサービス層は DAO を呼び出します。すべての dao メソッドで休止状態フィルターを有効にする必要があります。毎回明示的に session.enablefilter を呼び出す必要はありません。では、休止状態のセッションが作成されたときにインターセプターを呼び出すことができるように、春のトランザクション aop などを使用する方法はありますか?
私のサービス層:
@Service("customerViewService")
@Transactional
public class CustomerViewServiceImpl extends UFActiveSession implements CustomerViewService {
private static final Logger log = LoggerFactory.getLogger(CustomerViewServiceImpl.class);
private CustomerDAO daoInstance = null;
private CustomerDAO getCustomerDAO() {
if (daoInstance == null)
daoInstance = DAOFactory.getDao(CustomerDAO.class);
return daoInstance;
}
@Transactional(propagation=Propagation.REQUIRED, rollbackFor=DAOException.class)
public CustomerModel getCustomerModel() throws UFClientException {
CustomerModel model = null;
try {
Customer customerTbl = getCustomerDAO().getCustomerDetail(getUserName());
if (customerTbl == null) {
log.error("DAO-02: No entry found for Customer id- " + getUserName());
throw new UFClientException("DAO-02");
}
model = DozerConverter.hibernateToDto(customerTbl, CustomerModel.class);
}
catch (DAOException e) {
log.error("DAO-01: Not able to fetch entry from database for customer.");
throw new UFClientException();
}
return model;
}
}
私の道レイヤー
public class CustomerDAOImpl extends HibernateDaoSupport implements CustomerDAO {
@SuppressWarnings("unchecked")
public Customer getCustomerDetail(String email) throws DAOException {
try {
List<Customer> customers = getHibernateTemplate().find(sb.toString(), email);
if (customers.size() == 0)
return null;
return customers.get(0);
}
catch (Exception e) {
throw new DAOException(e);
}
}
あなたの助けに感謝!!