Is there a way to get Spring 2.5+ for autowire Hibernate domain objects

Is there a way to get Spring 2.5+ to auto-update Hibernate (3.0+) domain objects. I understand that there is a way to do this using AspectJ ( @Configurable ), but I would like to avoid using AspectJ.

Some Googling found this DependencyInjectionInterceptorFactoryBean class , but it seems to just live in the sandbox (and just in 2.0.x?).

I can create a 10-line Hibernate PreLoadEventListener to do this for auto-installation for me, but I really assumed that this would be something that org.springframework.orm.hibernate3 provided.

+4
source share
3 answers

The recommended way to provide dependency injection for instances outside of Spring is to use the AspectJ-based solution you mentioned. To my knowledge, Hibernate-related classes have been canceled in favor of the general approach described here .

Also note that you do not need @Configurable if you are using AbstractInterfaceDrivenDependencyInjectionAspect . As you said, you will need to use AspectJ either for download or at compile time. As a benefit, you get dependency injection for “corner cases” such as deserialization, as well as with this approach.

For a detailed example of how the templates offered by Ramnivas can be implemented and integrated, see here .

+2
source

Take a look at @Repository (and @Component) annotations. With Spring 2.5, the concept of “stereotyping” annotations introduced in Spring 2.0 has been expanded to include all these annotations with the new component scan functionality, as described in “Configuration with Annotation” in the Spring documentation chapter.

So this should work:

 @Repository public class HibernateClinic implements Clinic { private SessionFactory sessionFactory; public HibernateClinic(SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; } public Collection getVetTypes() { Session session = sessionFactory.getCurrentSession(); return session.createQuery("from VetTypes").list(); } } 

(Sample taken from Rossen Stoyanchev presentation at Metropolis 2008)

0
source

Could you give some example code?

I find the whole complex implementation of the anti-anemic area anti-pattern. I think it sounds great in theory, but in practice it is not so great.

What factors led you to use the rich domain approach?

-1
source

All Articles