This post originated from an RSS feed registered with Java Buzz
by Geoffrey Wiseman.
Original Post: Dependency Injection of Domain Objects in Hibernate?
Feed Title: Furious Purpose
Feed URL: http://www.jroller.com/diathesis/feed/entries/rss
Feed Description: Thoughts and experiences on technology and software.
An application with which I'm currently working is doing a reasonable amount of
dependency injection using Spring. It's difficult to inject dependencies into
the domain objects, as they are currently created either by client code or by
Hibernate itself. This results in code migrating upwards from the domain to
the service layer. The service layer, which was intended to be light connective
tissue, becomes increasingly thick and increasingly tightly coupled to the
domain.
In order to inject dependencies, there would need to be some control exercised
over the creation of these domain objects. The client code could be changed
to a factory method, which would give some injection possibilities, but I'm
not terribly fond of that. Under Hibernate we have even less options; I'd
have to implement a Hibernate interceptor that, after object creation, attempts
to inject dependencies.