Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
368 views
in Technique[技术] by (71.8m points)

dynamic - Hibernate ORM to map to non-classes

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...