0

Spring AOP advises are NOT kicking off around methods of objects returned by hibernate.

In my program, hibernate is returning list of objects of type CFolder.

What I want is when somebody calls getName() method on CFolder objects returned by the hibernate, I want Spring AOP to write "Before getName()" and "After getName()".

CFolder that represents folder

public class CFolder{
    String name;

    public String getName(){
        return name;
    }
}

Repository class that finds all the CFolders

@Service
@Repository
public class MyService implements MyServiceIfc<TypeTemplateMasterRepository> {

    @Autowired
    private CFolderRepository cfolderRepository;

    @Override
    @Transactional(readOnly=true)
    public void findAll(Class classz) throws Exception {

        List allFolders = cfolderRepository.findAll(); //Use hibernate to find all folders..
        for(int i=0; i < allFolders.size(); i++){
            CFolder cFolder = (CFolder) allFolders.get(i);
            System.out.println("The folder name is" + cFolder.getName()); //When 
        }
    }
}
bhattsu
  • 5
  • 1
  • 1

1 Answers1

0

Spring will only be able to proxy beans (apply AOP) which it controls, basically AOP will only work for beans inside the ApplicationContext.

If you want other objects intercepted you will need to use AspectJ and revert to either loadtime or compile time weaving of your aspects.

M. Deinum
  • 115,695
  • 22
  • 220
  • 224
  • Thank you - Just wondering if you have a Hello World example of how to achieve this..Have been struggling quite a bit on this one. – bhattsu Oct 02 '13 at 15:36
  • Also - is there a way to import or induct objects return by hibernate in Spring's ApplicationContext or say make it Spring Managed. If so is there an overhead? – bhattsu Oct 02 '13 at 15:53
  • No there isn't... The objects aren't spring managed and spring will never be able to touch them, not without loadtime/compile time weaving. – M. Deinum Oct 02 '13 at 18:35