Results 1 to 6 of 6

Thread: Dependency Injection on Hibernate Entities

Hybrid View

  1. #1
    Join Date
    Jun 2005
    Location
    Dallas, Texas
    Posts
    19

    Default Dependency Injection on Hibernate Entities

    Does anyone know if it is possible to use dependency injection on hibernate entities?

    I know I can create a DAO that returns a list of domain entities from a HibernateTemplate, but what if I want those 500 instances to be aware of some service? Does the DAO have to iterate through all 500 and provide the service instance? Or... can Spring do this automatically?

  2. #2
    Join Date
    Sep 2004
    Location
    Leuven, Belgium
    Posts
    1,853

    Default

    What you could do is make the DAO BeanFactoryAware. Cast the bean factory passed in to AutowireCapableBeanFactory and use that to 'wire' the entities you pulled from the DB.

    You could also do it with a Hibernate Interceptor. Take a look at the DependencyInjectionInterceptorFactoryBean that is in the Spring sandbox.

    Erwin

  3. #3
    Join Date
    Oct 2004
    Location
    Herndon, VA, US
    Posts
    648

    Default

    Here is an alternative approach to inject into domain objects
    --Jing Xue

  4. #4
    Join Date
    Aug 2004
    Location
    Ankara, Turkey
    Posts
    24

    Default

    Hello,
    Erwin, can you please give short code examples of how to use "DependencyInjectionInterceptorFactoryBean" ?

    Thank you,
    Turgay

  5. #5
    Join Date
    Jun 2005
    Location
    Dallas, Texas
    Posts
    19

    Default

    manifoldronin - the solution you suggest looks pretty clean on the surface.


    Do we have any success stories with this solution?

  6. #6
    Join Date
    Oct 2004
    Location
    Herndon, VA, US
    Posts
    648

    Default

    Quote Originally Posted by springland
    manifoldronin - the solution you suggest looks pretty clean on the surface.
    Do we have any success stories with this solution?
    Thank. Well, I have been using it on a couple of projects I'm currently working on (unfortunately none of them are OSS). I like it because it allows a more powerful and "vibrant" domain model. It really depends on your personal style on architecture/design I guess.
    --Jing Xue

Similar Threads

  1. Loosing my SecureContext
    By sklakken in forum Security
    Replies: 3
    Last Post: Jul 21st, 2005, 01:44 PM
  2. could not satisfy dependencies
    By springuser in forum Container
    Replies: 4
    Last Post: Apr 26th, 2005, 01:15 PM
  3. Replies: 1
    Last Post: Apr 25th, 2005, 07:37 PM
  4. Replies: 3
    Last Post: Nov 19th, 2004, 07:16 PM
  5. Replies: 2
    Last Post: Oct 5th, 2004, 08:36 AM

Posting Permissions

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