Results 1 to 3 of 3

Thread: How to store proxied object with Hibernate

  1. #1
    Join Date
    Sep 2004
    Posts
    2

    Default 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. #2
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    Lucky Luke,

    There is a very interesting thread on the architecture forum that discuss how / when to manage hibernate persisted beans using Spring: http://forum.springframework.org/showthread.php?t=9846

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

    Spring Modules Team
    http://irbouh.blogspot.com/

  3. #3
    Join Date
    Sep 2004
    Posts
    2

    Default

    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..

Similar Threads

  1. Replies: 6
    Last Post: Dec 12th, 2008, 04:33 AM
  2. Replies: 2
    Last Post: Oct 10th, 2005, 05:12 PM
  3. Loosing my SecureContext
    By sklakken in forum Security
    Replies: 3
    Last Post: Jul 21st, 2005, 01:44 PM
  4. Replies: 1
    Last Post: Mar 2nd, 2005, 02:12 AM
  5. Replies: 3
    Last Post: Nov 19th, 2004, 07:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •