Announcement Announcement Module
No announcement yet.
How to store proxied object with Hibernate Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to store proxied object with Hibernate

    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?

  • #2
    Lucky Luke,

    There is a very interesting thread on the architecture forum that discuss how / when to manage hibernate persisted beans using Spring:

    Last edited by Rod Johnson; Jan 18th, 2006, 10:39 AM.


    • #3
      Thanks, but I've already checked out that discussion. I know how to setup Hibernate to wire up my beans when loading them from database
      9works ok), but the problem is with proxied objects - I can't save them..