Hi there,
I'm migrating my application from using XDoclet to generate the hbm files to using JPA annotations. So far, I've managed to get things working by using AnnotationSessionFactoryBean instead of LocalSessionFactoryBean, but not as elegantly.
My problem relates to generating/exporting my schema ddl. With XDoclet, I'm able to use SchemaExport to look for **/*.hbm. Since these no longer exist with annotations, I have to configure it using hibernate.cfg.xml instead.
However, I'd like to keep everything configured via Spring beans. Currently, my application doesn't even have hibernate.cfg.xml. I just get LocalSessionFactoryBean to wildcard/autowire my beans, ala "classpath*:com/company/project/domain".
With JPA annotations, I have two options:
1) Explicitly specify the beans for AnnotationSessionFactoryBean, or
2) Bootstrap hibernate.cfg.xml
With 1, specifying the domain classes in the Spring config means I can't get Hibernatetools/SchemaExport to work out what classes have been mapped.
With 2, I have to rely on an external config and manually edit the mappings (can't autowire).
I'm wondering what other people have done to overcome this? Has anyone else encountered this problem?
Looking at the forums, I see indications that people have written their own Ant tasks or generated hibernate.cfg.xml. What isthe recommended approach? Is there an out of the box solution?
Should I subclass AnnotationSessionFactoryBean so that it can take Resource[] to enable autowiring and create my own Ant task to invoke Hibernatetools/SchemaExport to pass in a configuration object that is somehow bounded to my Spring config, so I can keep the configuration DRY?
Thoughts? Any help is much appreciated.
thanks,
dave
|