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:
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 persistence.xml
.orm.xml
in our case). That file is defined in our persistence.xml
.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.