Today i found a neat trick.
Typically when you inject an AnnotationSessionFactoryBean into one of your classes you end up with a SessionFactory on the other side. This is because Spring is doing its magic inside, proxying stuff so you end up with an easy way to instantiate hibernate sessions. The problem is that i wanted to be able to access the actual AnnotationSessionFactoryBean, so i could run the createDatabaseSchema method on it (retrieve the connection properties would be another use case).
So how do you inject the proxy, instead of the proxied object? You prefix the bean ref with the "&" sign, like so: <property name="sessionFactory" ref="&sessionFactory"/> If you want to do it inside, for instance, anything that extends AbstractTransactionalJUnit4SpringContextTests, you can do it like this: sessionFactoryBean = (AnnotationSessionFactoryBean) super.applicationContext.getBean("&sessionFactory"); Hope it helps somebody :)