Spring – execution of Spring AOP Around advice in DAO returns null in service

aop, spring

I have written my pointcut and custom around advise, which will execute one Dao method.

Pointcut

@Pointcut("execution(* com.dao.*.get*(..))")    public void creditPointcut(){    }

Around Advice

@Around("creditPointcut()")     public void around(ProceedingJoinPoint point) throws Throwable{        LOGGER.info("Method name: "+point.getSignature().getName()+" started");        point.proceed();        LOGGER.info("Method name: "+point.getSignature().getName()+" ended");    }

Target – Dao Method

public Account getAccountDetails(int accntNo) {        Session session = sessionFactory.getCurrentSession();        Query query = session.createQuery("from Account where accountNo=:acctNo");        query.setInteger("acctNo", accntNo);        Account account = (Account)query.list().get(0);        return account;    }

But, this advice returns null account in my service.

Service layer method

@Override    @Transactional(isolation=Isolation.READ_COMMITTED )    public Account getAccountDetails(int accntNo) {        Account account = accountDao.getAccountDetails(accntNo);        return account;    }

Please help me why i am getting null account in my service, after executing the around advice in Dao.

Best Solution

That's because you are not returning anything from the advice:

@Around("creditPointcut()") public Object around(ProceedingJoinPoint point) throws Throwable{    LOGGER.info("Method name: "+point.getSignature().getName()+" started");    Object ret = point.proceed();    LOGGER.info("Method name: "+point.getSignature().getName()+" ended");    return ret;}