I feel a bit silly asking this question because it seems like it should be obvious but none of the search terms I've used have come up with anything definite.
We have a suite of applications which used JDBC calls strewn throughout the code. The first phase was to refactor this to use DAOs and this worked well. The next phase was to replace the JDBC code with a Hibernate equivalent and to use Spring.
As a handful of the DAO classes are refactored we run a set of unit tests to make sure we haven't broken anything. These tests worked OK during the first phase using the JDBC DAOs. In the second phase of using the Hibernate DAOs we're getting MappingExceptions.
The reason for these exceptions is clear but we cannot figure out how to solve the problem.
The majority of the DAO classes are fairly atomic and know nothing about other DAOs. There are many combinations of DAOs to make any one application and, in the JDBC version, each DAO only needed the JDBC connection to bring it all together.
In the Hibernate DAO version the sessionFactory is also needed together with the necessary mappings. Although it is clear that the mappings can be specified for an application, the DAO level programmer has no idea what applications his code will be used in.
We discussed this internally and thought there must be a call to do something like; add my mappings to the sessionFactory if not already there and give me a connection. Such a call does not appear to exist.
This all worked a treat using the JDBC DAOs but seems a nightmare in Hibernate. Surely we can't be the first to come across this or are we missing something obvious?
|