Results 1 to 5 of 5

Thread: pointcut on entityManager

  1. #1
    Join Date
    Dec 2005
    Posts
    18

    Default pointcut on entityManager

    Hello,

    I am playing with spring 2 aop features, I try to intercept call to the 'persist' method of entityManager in order to do something with the instance candidate for persistance. Since I do not know which implementation of javax.persistence.EntityManager I use in my code I cannot declare properly the pointcut expression. When I display this.entityManager.getClass().getName(), I just get the proxy.

    I use hibernate so I tried

    pointcut="execution(* org.hibernate.ejb.AbstractEntityManagerImpl.persis t(..)) and args(entity)" arg-names="entity"

    but with no success. The objects are correctly persisted but the aspect is not called. The same aspect works correctly when the pointcut expression concerns one of my classes.

    In the same time I manage to work with several other aspects (with / without parameters, before/after/...) but the poincut expression always targets a class of my application.

    Thanks for your opinion, and sorry if my question seems a bit naive (I am pretty new to aop in the spring 2.0 fashion). By the way, this question may be more related to hibernate than spring.

    Gengis

  2. #2
    Join Date
    Jun 2006
    Location
    SF Bay Area, California
    Posts
    524

    Default

    The aspect declared in this manner will apply only to the bean declared in your application context. I suspect that you don't have a bean for entity manager (and you probably don't want to have one due to other design considerations).

    A solution in such cases is to use the AspectJ weaver (which can apply to beans and non-beans equally well).

    -Ramnivas
    Ramnivas Laddad (Follow me on Twitter)
    AspectJ in Action: Enterprise AOP with Spring Applications (2nd edition). Now available!

  3. #3
    Join Date
    Dec 2005
    Posts
    18

    Default

    Thanks ramnivas for your answer,

    I use aspectj annotations with no problem but I did not manage to 'intercept' anything related to javax.persistence.EntityManager, even with joinpoints like this(javax.persistence.EntityManager) or target(javax.persistence.EntityManager)

    In your last post you mention the 'AspectJ weaver', do you have in mind some aspectj features not covered by spring aop ?

    Thanks, and congratulation for spring 2.0 release

  4. #4
    Join Date
    Nov 2007
    Posts
    177

    Default

    Quote Originally Posted by Gengis View Post
    Thanks ramnivas for your answer,

    I use aspectj annotations with no problem but I did not manage to 'intercept' anything related to javax.persistence.EntityManager, even with joinpoints like this(javax.persistence.EntityManager) or target(javax.persistence.EntityManager)

    In your last post you mention the 'AspectJ weaver', do you have in mind some aspectj features not covered by spring aop ?

    Thanks, and congratulation for spring 2.0 release
    Have you managed to find a solution to your problem? If so please share it. I am very interested.

  5. #5
    Join Date
    Jul 2010
    Location
    Venice, Italy
    Posts
    709

    Default

    Use full-blown AspectJ, either ctw or ltw, to advise non-Spring beans. Just read the framework reference guide it's all clearly specified.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •