Announcement Announcement Module
Collapse
No announcement yet.
Dependency Injection on Hibernate Entities Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

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

    Comment


    • #3
      Here is an alternative approach to inject into domain objects

      Comment


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

        Thank you,
        Turgay

        Comment


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


          Do we have any success stories with this solution?

          Comment


          • #6
            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.

            Comment

            Working...
            X