On Fri, Apr 10, 2015 at 12:25 PM, Sanne Grinovero <sanne(a)hibernate.org>
I'm considering solving a complex issue in Hibernate Search by having
it add a couple of "system entities" to the set of user defined
Do we have any example on how I'd do that?
Yep. This is exactly what Envers does. Currently, I have Envers
using org.hibernate.boot.spi.AdditionalJaxbMappingProducer for this
purpose. That was a transitory fix since Envers already build DOM
(represeting the hbm.xml of the entities they want to add) and because I
did not want to waste cycles atm rewriting all of Envers bootstrapping to
"be more correct" and generate model classes directly.
We could start to develop the more correct approach for you to use.
Basically you would generate org.hibernate.mapping model instances yourself
and have them added to the "metadata sources".
Either way, you'd also be interested in looking at their "flush cycle
hooks" as you would probably have similar requirements.
Bonus brownies if we could figure out a way to mark these as
"internal".. i.e. it would be nice to not allow user code
these, have other entities relate to these, or mention them in HQL
I'd need a backdoor to allow Search code to do that though :)
Of course I don't expect us to be able to hide the physical tables.
This does not exist today. Blocking them from being used in associations
would be very detrimental to Envers if we were ever to expose this
generically. But your other 2 points would work wonderfully with Envers
too. We can add that for post-5.0 if you wish. I don't see it as
critical. As far as querying, I'd suggest marking these are not allowing
implicit polymorphism (are they returned, e.g., from a query like `from
I guess I could get pretty far by using JDBC rather than defining it
as an entity, but I'd rather avoid that. If that were my only option,
I'd at least want to extend the schema generation/validation tasks to
include by custom table.
If you do go this route, this is pretty easy now in 5.0. You'd simply
obtain the Database from the Metadata (preferrably while building, so
specifically from the org.hibernate.boot.spi.InFlightMetadataCollector).
From there you could add tables, sequences, etc directly. This is
drives schema export, update, etc.