How to pointcut hibernate when i use spring aop?

浪子不回头ぞ 提交于 2019-12-12 03:04:19

问题


I think as an entry point to the session, but seems to have failed. Whether my configuration? Here is my spring config.

<bean id="aspect" class="org.bigbean.common.aop.DaoAspect" />
<aop:config>
    <aop:aspect ref="aspect">       
        <aop:around pointcut="execution(* org.hibernate.SharedSessionContract.createQuery(java.lang.String))"
            method="aroundAdvice" />
    </aop:aspect>
</aop:config>

follow is my class

    public Object aroundAdvice(ProceedingJoinPoint pjp) throws Throwable {
    System.out.println("aroundAdvice");
    String hql = (String) pjp.getArgs()[0];
    if(hql.indexOf("update") > -1){
        StringBuilder sb = new StringBuilder();
        int temp = hql.indexOf("where");
        if(temp > -1){
            sb.append(hql.subSequence(0, temp));
            sb.append(",updateDate = :updateDate ");
            sb.append(hql.substring(temp));
        }else{
            sb.append(",updateDate = :updateDate ");
        }
        hql = sb.toString();
        mark = true;
    }
    Object retVal = pjp.proceed(new Object[] { hql });
    return retVal;
}

回答1:


Unless you are using load-time weaving or compile-time weaving, Spring AOP is proxy-based. This means you can only pointcut in objects created by Spring (i.e. Spring beans). You are trying to pointcut an internal Hibernate object which is most likely created inside hibernate using the normal new SharedSessionContract() construct.



来源:https://stackoverflow.com/questions/14576785/how-to-pointcut-hibernate-when-i-use-spring-aop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!