|
|
I'm usign Spring+Hibernate+@AspectJ and i configured a few pointcuts so that every time a method is call there'd be a console output as a form of logging what's happening. The problem i'm having is that when the beans are retrieved from my DataBase they are not Decorated and so the logging methods are not called. Is there a way of configuring Hibernate to instantiate Decorated objects?
Originally Posted by joni.lokyI'm usign Spring+Hibernate+@AspectJ and i configured a few pointcuts so that every time a method is call there'd be a console output as a form of logging what's happening. The problem i'm having is that when the beans are retrieved from my DataBase they are not Decorated and so the logging methods are not called. Is there a way of configuring Hibernate to instantiate Decorated objects?
You using AspectJ or Spring AOP? Are you trying to weave domain objects? If so, you need to use AspectJ, read through the Chapter 6 of the documentation...
Tnkx!
I don't know if i understood it right but, If I add an @Configured annotation to my beans, lt;context: spring-configured/gt; to my spring-beans.xml file and spring-aspects.jar to my project, then will Hibernate instatiate decorated objects? Then it will the logging work?
Originally Posted by joni.lokyTnkx!
I don't know if i understood it right but, If I add an @Configured annotation to my beans, lt;context: spring-configured/gt; to my spring-beans.xml file and spring-aspects.jar to my project, then will Hibernate instatiate decorated objects? Then it will the logging work?
@Configurable allows you to inject your Hibernate object with Spring beans. So if you have a spring bean that performs quot;loggingquot; or whatever else, you can use @Configurable approach to inject the dependency into your hibernate objects and then let the dependency do its work (like logging).
I don't wanna inject my Hibernate objects with a bean that logs. I'm using Aspects so that before and after every method is called logging would take place. The problem I'm having is that my hibernate objects are not being instantiated by spring so what i get is not a proxy (or decorated version of my beans) and therefor the advice that logs is not being called.
Originally Posted by joni.lokyI don't wanna inject my Hibernate objects with a bean that logs. I'm using Aspects so that before and after every method is called logging would take place. The problem I'm having is that my hibernate objects are not being instantiated by spring so what i get is not a proxy (or decorated version of my beans) and therefor the advice that logs is not being called.
If you want to do that you have to use AspectJ, it can't be done with Spring AOP. One option you have is to use AspectJ compiler and weave your domain objects at compile time with your logging code. You can refer to AspectJ documentation for any additional information you may have.
You can also use hibernate interceptor by itself for logging, depending on the type of logging you intend to do. org.hibernate.Interceptor provides callback methods for Hibernate lifecycle so you if you want to log things like saves, updates, deletes... you can do that without AOP - just add your interceptor to the session and log from it. a nice introduction on hibernate interceptors is here articles/9-i...roducti-1.html
No...It's not saves and updates i wanna log. I wanna log the work my beans are doing. I guess I'll have to look into Weaving at compile time with AspectJ. Thnx! |
|