How can this be accomplished with minimal impact to the source code so that common libraries may be shared between the two applications? A NamingStrategy class did the job nicely.
http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/session-configuration.html#configuration-namingstrategy
The only difference in setting up the SessionFactory for each application was to add one line in the Configuration setup. Not very invasive and I have been able to reuse a lot of code, including all my DAOs and Hibernate annotations.
<dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>4.1.4.Final</version> </dependency> <dependency> <groupId>org.hibernate.common</groupId> <artifactId>hibernate-commons-annotations</artifactId> <version>4.0.1.Final</version> </dependency>
Additional Resources
- http://www.petrikainulainen.net/programming/tips-and-tricks/implementing-a-custom-namingstrategy-with-hibernate/
- Google search for hibernate and namingstrategy
- http://stackoverflow.com/questions/5050538/hibernate-improvednamingstrategy-overrides-table-name-in-entity
- http://stackoverflow.com/questions/4313095/jpa-hibernate-and-custom-table-prefixes
No comments:
Post a Comment