休眠ORM映射到非类 [英] Hibernate ORM to map to non-classes

查看:170
本文介绍了休眠ORM映射到非类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为应用程序平台构建存储子系统。元模型将是动态的(在运行时可以改变)。我有一个元模型来表示模型结构(完整的伪类与属性,关系,层次结构等)。由于元模型是动态的,因此在元模型中不存在与伪类相对应的Java类。

我知道Hibernate使用元模型在类和表之间进行映射,根据类模型和填充对象生成查询。我想知道是否有一种方法让Hibernate为元类而不是类实现此目的,而是使用代理对象而不是具体的POJO。

基本上我想用我的元模型来定义O / R映射而不是Java类。这可以用Hibernate来实现吗?我已经在运行时动态生成实际的类,并使用CGLib和映射这些类的想法,但我希望有更好的方法。



我希望有一种方法可以像Hibernate Proxy一样使用这种方法,但不能继承POJO,只能保留为纯代理。



想法?

解决方案

https:// github。 com / hibernate / hibernate-orm / tree / master / hibernate-core / src / test / java / org / hibernate / test / dynamicentity 代表3种方法可以实现这一点。我会看看tuplizer2的方法。


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?

解决方案

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.

这篇关于休眠ORM映射到非类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆