如何在使用hibernate时动态添加字段 [英] how to add fields dynamically when using hibernate

查看:369
本文介绍了如何在使用hibernate时动态添加字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题

使用Hibernate动态添加和删除实体。

我确定这是一种常见的情况,大多数企业应用程序都需要一定程度的定制。那么最好的办法是什么?理想情况下,它不应该需要重新编译,并平滑地创建/删除架构中的字段,并允许应用程序继续工作。



如果它只是一个更新xml的问题,(非常确定代理类是必需的)那么模式如何重新加载?

感谢百万的输入

注意:如果您认为有更好的解决方案,我也是所有的耳朵,谢谢

解决方案

我不认为这是一个非常常见的用例,因为Aaron认为它需要一段时间才能确定下来。



模式更新也不是简单的。即使认为Hibernate确实提供了程序化模式更改,但它仅限于简单的事情,如添加/删除字段。这可能适用于你,但是如果数据类型或列的可空性发生变化,Hibernate将不会为你更新它。



你可能想要考虑OneToMany关系并将数据作为一行存储在单独的表中,假设您可以接受另一个连接的开销。


The problem

Dynamically add and remove fields to entities on the fly using Hibernate.

I m sure this is a common scenario, most enterprise applications will require some level of customization. so what is the best way to do it? also ideally it should not require a recompile and smoothly create/remove the field in the schema and allow the application to continue working.

If its just a question of updating the xml, ( i m pretty sure the proxy classes are required) then how does the schema gets reloaded?

Thanks a million for input

Note: If you think there is a better solution I m also all ears thanks

解决方案

I don't think it's a very common use case and as Aaron suggests it's going to take you quite a while to nail this down.

The schema update will not be straightforward either. Even thought Hibernate does offer programmatic schema changes, it's limited to simple things like adding/removing fields. That might work for you, but if the data type or nullability of a column changes, Hibernate won't update it for you.

You may want to consider a OneToMany relationship and store the data as a row in a separate table, assuming you can accept the overhead of another join.

这篇关于如何在使用hibernate时动态添加字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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