问题
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