I've just recently started using hibernate and so I apologize if this is a stupid question.
I want to package some of my code into a module which different applications can then utilize. For example, a package that handles sending SMS messages. This package does some database work to get basic config data and then might do some transaction logging. This will then be added to applications requiring SMS functionality. The package would therefore require the calling application to contain the specific config and logging tables required by the package.
My problem is that in order to write the hibernate methods that get the config and do the logging it needs to know of the hibernate specific DOA objects. The problem is these objects are only generated when we create the specific application database mapping.
We are in a similar situation, so here's what we do:
- All entities are contained in our library and thus the DAOs have full knowlegde of those entities.
- If an application needs more fields in an entity, it subclasses the base entity and subclasses the corresponding DAO as well (which is parameterized using generics).
- The library doesn't contain any
persistence.xml, but our applications define one, listing the library jar using a
<jar-file>element. Note that for this to work, all DAOs have to use the same persistence unit, which is defined in that
- The application will have to provide the tables defines in the library, but those can be overwritten using a XML file (named
orm.xmlin our case). That file is defined in our
Of course, you can reduce complexity if you don't have to extend your library with application specific code. In that case you can put the
persistence.xml into the lib, use a different persitence unit etc.