休眠运行时更改架构 [英] changes to the schema while hibernate is running

查看:64
本文介绍了休眠运行时更改架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个高使用率的系统,该系统映射了一些只读表和视图。在不同的时间点,我需要通过外部连接到数据库来用较新的版本替换这些表中的数据。

I'm working on a high usage system which maps a few "read only" tables and views. At various points in time I need to replace the data in these tables with a newer version by connecting to the database externally.

我们使用的是Postgres 8.3+和Hibernate 3.2。 6。外部的更新过程将通过PSQL连接到数据库。

We are using postgres 8.3+ and hibernate 3.2.6. The external "update" process will be connecting to the db via PSQL.

对于某些较小的表,在事务中进行截断和插入应该令人满意。

For some of the smaller tables, a truncate and insert within a transaction should be satisfactory.

但是有些表很大,并且truncate / insert方法可能会将表锁定太长时间。

However some of the tables are quite large and the truncate/insert method will probably lock the table for too long.

在这种情况下,我正在考虑以下任一方法:

In this case I am considering either:

1)表重命名-即在将休眠映射到table_a时将新数据加载到table_b中,然后从table_b-中执行表重命名- >通过PSQL table_a

1) table rename - ie load new data into table_b while hibernate is mapped to table_a and then perform a table rename from table_b->table_a via PSQL

-或-

2)始终将休眠映射到视图,并且当table_b为

2) always map hibernate to a view, and when table_b is populated re-define the view to route to table_b instead of the now redundant table_a.

-或-

填充后,重新定义视图以路由到table_b而不是现在的多余table_a。 3)创建并填充新的架构,并在新架构就绪后更改休眠用户的搜索路径

3) create and populate a new schema, and change the hibernate user's search path once the new schema is ready

我不确定这些方法的影响100%在冬眠之内,尽管我即将尽我所能,将很难测试冲突(即在重命名时对表的休眠查询),因此将不胜感激一些理论观点。

I'm not 100% sure of the repercussions of these approaches within hibernate, and although I am about to test as best I can it will be hard to test collisions (ie a hibernate query to the table at the point it is being renamed) so some theoretical opinions would be much appreciated.

如果有人尝试过类似的方法或知道潜在的陷阱,我将非常感谢。

if anyone has attempted similar approaches or knows of the potential pitfalls I'd be very grateful..

p。

推荐答案

您可以利用PostgreSQL的 MVCC 通过重命名事务中的表。从任何其他正在进行的交易和将来的交易的角度来看,这将确保原子性。

You could take advantage of PostgreSQL's MVCC by renaming the tables inside a transaction. This will ensure atomicity from the point of view of any other running and future transactions.

从Hybernate的角度来看,使高速缓存无效应该足以确保所检索数据的新鲜度。

From the point of view of Hybernate, invalidating the cache should be enough to ensure the freshness of retrieved data.

这篇关于休眠运行时更改架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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