Page 5 of 6 FirstFirst ... 3456 LastLast
Results 41 to 50 of 58

Thread: How Common to Spring Manage Beans Created By Hibernate?

  1. #41

    Default

    where can I find the code of org.springframework.orm.hibernate.support.Dependen cyInjectionInterceptorFactoryBean ?

  2. #42
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

    In the sandbox directory in CVS.
    Rod Johnson - GM, SpringSource Division, VMware
    http://www.springsource.com
    Spring From the Source

  3. #43

    Default

    I looked there but could not find it. Could someone give the exact location (or maybe a link)?. Thanks in advance for your help.

  4. #44

    Default

    I found it! I was lokking in the wrong directory. Thnaks for your help.

  5. #45
    Join Date
    Aug 2004
    Location
    berkeley, ca, usa
    Posts
    13

    Default Autowiring an ApplicationContextAware type

    Quote Originally Posted by Rod Johnson
    The fundamental configuration step is to add an appropriately configured DependencyInjectionInterceptorFactoryBean as a Hibernate interceptor in your Hibernate SessionFactory. Do this via the "entityInterceptor" property of the LocalSessionFactoryBean, for example. ....
    Everything appears to be being wired up correctly for me using the three new classes from the sandbox with 1.1.1, except that my Hibernate persisted object does not get its setApplicationContext method called after being rehydrated (all the other properties are correctly wired). It implements ApplicationContextAware, but is there something additional that I need to do here?

    Thanks for any help.

  6. #46
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

    Everything appears to be being wired up correctly for me using the three new classes from the sandbox with 1.1.1, except that my Hibernate persisted object does not get its setApplicationContext method called after being rehydrated (all the other properties are correctly wired).
    It won't call setApplicationContext() with the autowiring approach. Autowiring does not register the object with the application context as a prototype, it merely does Dependency Injection based on resolving properties. This is consistent with the BeanFactory semantics on autowiring existing objects with dependencies from a factory.

    If you want the ApplicationContextAware and other lifecycle interfaces to be invoked, you should use full factory management of your beans by defining them as prototypes.

    Guess I should update the Javadoc to indicate this.
    Rod Johnson - GM, SpringSource Division, VMware
    http://www.springsource.com
    Spring From the Source

  7. #47
    Join Date
    Aug 2004
    Location
    berkeley, ca, usa
    Posts
    13

    Default thanks

    Quote Originally Posted by Rod Johnson
    If you want the ApplicationContextAware and other lifecycle interfaces to be invoked, you should use full factory management of your beans by defining them as prototypes.
    Ah, that makes sense now. After changing autowire to 0 and defining the prototypes in managedClassNamesToPrototypeNames, it works great.

    Thanks...

  8. #48
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

    I've updated the Javadoc. Thanks for bringing this to my attention.
    Rod Johnson - GM, SpringSource Division, VMware
    http://www.springsource.com
    Spring From the Source

  9. #49
    Join Date
    Aug 2004
    Location
    Hawaii, US
    Posts
    225

    Default

    There is a slight inconsistency with how Hibernate might wire a bean's ID and how this new interceptor is doing it.

    The interceptor will use BeanWrapper.setPropertyValue to set the ID. This will not work if the bean has only a getter for the ID (and only field access for the ID). If no setter exists, then a NotWritablePropertyException is thrown.

    Hibernate, on the other hand, is able to use field access to set properties of a bean.

    I wonder if the interceptor should first try setPropertyValue, and if it fails, to try setting the field directly? We removed our setId() method to make it more clear users aren't able to set this. We'll set it to private for now, but if we're able to set the ID via its field, that would be even better.

    Any reason not to?

  10. #50
    Join Date
    Aug 2004
    Location
    Hawaii, US
    Posts
    225

    Default

    Actually, turns out I have to create a public setId() to get it to work with setPropertyValue.

    I'd like to be able to work with private setters, or even better yet, just accessing the field. If this is a good idea, I'll post the patch.

Similar Threads

  1. Hibernate Long Session Per Flow?
    By akw in forum Web Flow
    Replies: 21
    Last Post: Dec 12th, 2005, 08:06 PM
  2. Spring container fails with no exception
    By naor in forum Container
    Replies: 9
    Last Post: Oct 1st, 2005, 03:39 PM
  3. Spring code remarks
    By Alarmnummer in forum Architecture
    Replies: 18
    Last Post: Apr 7th, 2005, 07:17 AM
  4. Replies: 14
    Last Post: Feb 21st, 2005, 05:41 PM
  5. Mixing hibernate & spring into single beans
    By ImanRahmati in forum Container
    Replies: 1
    Last Post: Dec 21st, 2004, 07:26 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
  •