An usual domain model consisting of POJOs is mapped to be persisted with Hibernate (works ok).
I am using the Spring Framework AOP cappabilities - so my POJOs are proxied by Spring to add desired aspects.
For example, lets say that a class Product is mapped to be persisted with Hibernate. Then, in the Spring mapping files, it is defined to be intercepted in a way that every method is logged (maybe not the best example). In a runtime, every object that is obtained via Spring Bean Factory and manipulated in the program code behaves like it is a Product, but if you invoke getClass().getName() on it you will get something like $Proxy123.
The problem arises when I need to store (save, update, whatever) these proxied objects. Hibernate probably tries to determine the class name, so it tries to persist %Proxy123 instead of Product.
How can I tell Hibernate "that's a proxy that can't be stored but it can give you the right object if you ask", when it try to store (or do something else) my object?
Probably the solution is somewhere in net.sf.hibernate.Interceptor interface. Hibernate3 adds Interceptor.getEntityName() method that might be helpful (I am not sure), but Spring still does not support Hibernate3.
Anyone got the solution?
|