问题
I'm building the storage subsystem for an application platform. The metamodel will be dynamic (changeable at runtime). I have a metamodel to represent the model structure (complete with pseudo-classes with properties, relationships, hierarchy, etc.). Because the metamodel is dynamic there are no Java classes corresponding to the pseudo-classes in the metamodel.
I know that Hibernate uses a metamodel to map between classes and tables, generating queries based on the class model and populating objects. I'm wondering if there's a way for Hibernate to do this for metaclasses instead of classes, populating proxy objects instead of concrete POJOs.
Basically I want to use my metamodel to define the O/R mapping instead of Java classes. Is this doable with Hibernate? I've kicked around the idea of dynamically generating actual classes at runtime with something like CGLib and mapping those, but I'm hoping there's a better way.
I'm hoping that there's a way to use something like the Hibernate Proxy for this, only not subclassing a POJO, just remaining as a "pure" proxy.
Thoughts?
回答1:
The sub-folders in https://github.com/hibernate/hibernate-orm/tree/master/hibernate-core/src/test/java/org/hibernate/test/dynamicentity represent 3 ways you might accomplish this. I'd look at the tuplizer2 approach.
来源:https://stackoverflow.com/questions/12061289/hibernate-orm-to-map-to-non-classes