Весна, Транзакции, Спящие Фильтры - PullRequest
3 голосов
/ 08 июня 2011

Я использую декларативные транзакции в Spring.У меня есть сервисный слой, который помечен как «Транзакционный».Этот сервисный уровень вызывает DAO.Мне нужно включить фильтр гибернации во всех методах Дао.Я не хочу каждый раз явно вызывать session.enablefilter.Так есть ли способ с использованием весенней транзакции и т. Д., Чтобы при создании сеанса гибернации можно было вызывать перехватчик?

Мой уровень обслуживания:

@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);
    }
}

Благодарим Вас за помощь !!

1 Ответ

1 голос
/ 08 июня 2011

Вы можете создать свой собственный перехватчик и применить его к методам, которые имеют транзакционный характер:

@AroundInvoke("@annotation(transactional)")
public ... handle(Transactional transactional) {
 ...
}
...