Announcement Announcement Module
Collapse
No announcement yet.
dynamic proxies och hibernate Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • dynamic proxies och hibernate

    Hi all,
    I'm integrating hibernate with spring's acegi (security framework). I want to add security checks on a persisted objects methods.
    Becuase it is spring, I add a proxy (dynamic or cglib) with in front of the actual method. This all works fine but when use it together with load runner. The class is of course different.
    Hibernate complains that it does not have a persister for the specific class.

    What I do in detail, is that in the instantiate-method in hibernate's interceptor:
    -----
    public Object instantiate(Class clazz, Serializable id) throws CallbackException {

    create object with a spring proxy in front
    return the object.

    }

    Later when it loads it I get the error:
    net.sf.hibernate.MappingException: No persister for: no.abmu.organisationregister.domain.LanguageImpl$$ EnhancerByCGLIB$$ffe2eb75
    at net.sf.hibernate.impl.SessionFactoryImpl.getPersis ter(SessionFactoryImpl.java:347)
    at net.sf.hibernate.impl.SessionImpl.getClassPersiste r(SessionImpl.java:2690)
    at net.sf.hibernate.impl.SessionImpl.getPersister(Ses sionImpl.java:2697)
    at net.sf.hibernate.loader.Loader.loadFromResultSet(L oader.java:619)
    at net.sf.hibernate.loader.Loader.instanceNotYetLoade d(Loader.java:586)
    at net.sf.hibernate.loader.Loader.getRow(Loader.java: 501)
    at net.sf.hibernate.loader.Loader.getRowFromResultSet (Loader.java:213)
    at net.sf.hibernate.loader.Loader.doQuery(Loader.java :281)
    at net.sf.hibernate.loader.Loader.doQueryAndInitializ eNonLazyCollections(Loader.java:133)
    at net.sf.hibernate.loader.Loader.doList(Loader.java: 1033)
    at net.sf.hibernate.loader.Loader.list(Loader.java:10 24)
    at net.sf.hibernate.hql.QueryTranslator.list(QueryTra nslator.java:854)
    at net.sf.hibernate.impl.SessionImpl.find(SessionImpl .java:1544)

    Of course not really surpringsly but I expected to solve this somehow, but I have to admit that I'm stuck.

    The problem is general in the sense that it would be nice to add a dynamic proxy to a persistent object for other reasons than the above.

    Does anyone have any suggestions?

    I know that there are a number of workarounds but this will be by far the most simple.
    Regards
    Erik Romson

  • #2
    Erik,

    If you are proxying your persistent objects I think your are going to run into problems not only for the reason you have shown. Currently, CGLIB cannot create a proxy of a proxy and if you manage to get this up and running it will die when Hibernate tries to create its proxy.

    In my experience it is better to put container services such as security and transactions on service objects rather than persistent objects for this very reason. Have you seen the sample apps with Spring? They provide some good starting points for this kind of architecture.

    Rob

    Comment


    • #3
      Hibernate 2.x looks for persister by class. Hence it won't work with either CGLIB or dynamic proxies. You would need to patch Hibernate to change that. Probably not rocket science, but probably not a good idea either. I believe Hibernate 3 will have a more flexible mapping.

      So you can't do what you want to do, unless you advise objects without Hibernate knowing. I've had good results from a strategy where I advised objects to add custom change tracking, with the service layer seeing the advised objects, but the proxies merely being a view on top of the targets, which Hibernate persisted. The proxies automatically proxied on relationship navigation. It wasn't particularly simple, and you'd probably be best to avoid it if you can, but it worked fine.

      Comment


      • #4
        Thank you for your answers.
        I needed some traversing to different objects with different access to different methods.
        But luckily my customer listens to reason so we changed that requirement.
        I'll see later what hibernate 3 brings.
        /erik

        Comment

        Working...
        X