读书人

Hibernate Envers施用笔记

发布时间: 2012-10-09 10:21:45 作者: rapoo

Hibernate Envers使用笔记

?

在项目中尝试使用Envers对实体加入版本控制,以达到对实体更动进行监控的目的。

?

Hibernate Envers版本:envers-1.2.2.ga-hibernate-3.3

?

?

Envers部分功能:

?

    支持JPA规范中定义的所有映射关系支持Hibernate中扩展自JPA规范的映射关系,如自定义类型,"简单类型(String, Integer等)"的集合使用"revision entity"为每个revision提供日志记录查寻历史数据

Envers目前不支持的功能:

?

    BagsCollection of compononents@OneToMany + @JoinColumn

?

关于revision:

?

?Reference文档中Basically, one transaction is one revision (unless the transaction didn't modify any audited entities).

As the revisions are global,having a revision number, you can query for various entities at that revision, retrieving a (partial) view of the database at that revision.

You can find a revision number having a date, and the other way round, you can get the date at which a revision was commited.

---------------------

?

?

在JPA或Hibernate配置文件中加入Envers相关配置(为不同的EJB event添加对应Envers的listener)。

?

对于需要Audited功能的实体,在类上添加"@Audited"注释。如果只需要对类的部分property添加audit控制,则只要为对应property添加"@Audited"注释。

?

?

?

读书人网 >软件架构设计

热点推荐