Hibernate ORM to map to non-classes

懵懂的女人 提交于 2019-12-12 05:36:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!