休眠每个表中的审核列,而不必在每个< class>中重复它们定义? [英] Hibernate audit columns in each table without repeating them in each <class> definition?

查看:46
本文介绍了休眠每个表中的审核列,而不必在每个< class>中重复它们定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用休眠模式时,是否可以指定抽象基类中是否存在某些列(包括id,审计列等)?这似乎是相当普遍的做法.尤其是对于审计?

When using hibernate is it possible to specify that certain columns (including id, audit columns, etc) are present in an abstract base class? This seems like a fairly common practice. Especially for auditing?

但是,我需要让这个基类仅为审计列指定列名和属性/方法名.虽然Integer id列存在于抽象基类中,但我需要在具体类的hibernate中定义id元素,因为每个具体类将使用不同的序列.

However, I need to have this base class just specify the column names and property/method names for just the audit columns. While the Integer id column exists in the abstract base class, I need to define the id element in hibernate in the concrete class, as each concrete class will use a different sequence.

我最初开始寻找一种简单地将hbm文件包括"到另一个hbm文件中,并在一个地方定义审核列的方法,但是没有找到解决方案.然后,我开始研究使用abstract = true的类,但似乎这些类仍需要一个id,在我的情况下这实际上不起作用.

I originally started looking for a way to simply "include" an hbm file in another hbm file and define the audit columns in a single place, but didn't find a solution for that. Then I started looking at using the class with abstract=true, but it seems that those classes still need an id, which doesn't really work in my situation.

@MappedSuperClass似乎可以在注释世界中使用,但是使用.hbm.xml文件时我找不到解决方案吗?

Seems that @MappedSuperClass would work in the annotation world, but I have not been able to find a solution when using .hbm.xml files?

有人可以举例说明我如何能够做到这一点吗?

Can someone please provide an example of how I might be able to accomplish this?

推荐答案

Hibernate似乎不支持XML映射的超类,因此您可以尝试使用 abstract union对其进行仿真-subclass ,如本文.但是,这很麻烦.

Hibernate doesn't seem to support mapped superclass in XML, so you may try to simulate it using abstract and union-subclass as described in this article. It's pretty cumbersome,though.

这篇关于休眠每个表中的审核列,而不必在每个< class>中重复它们定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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