我如何通过@Any注释的属性进行双向映射? [英] How can I do bi-directional mapping over @Any annotated property?

查看:106
本文介绍了我如何通过@Any注释的属性进行双向映射?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在本文中 http://www.jroller.com/eyallupu/entry/hibernate_the_any_annotation 以及在这个问题中如何使用Hibernate @任何相关的注释? ,解释了如何使用@Any注解。但是,我怎样才能获得每张DVD / VHS / BOOK的借阅?如何在DVD / VHS / BOOK上做映射定义?

In this article http://www.jroller.com/eyallupu/entry/hibernate_the_any_annotation and also in this question How to use Hibernate @Any-related annotations?, how @Any annotation can be used was explained. But how can I get borrows for each DVD/VHS/BOOK? How can I do mapping definition on DVD/VHS/BOOK?

推荐答案

我不认为 这是支持的,正如文件中提到的那样:

I don't think this is supported and, as mentioned in the documentation:


2.4.5.2。 @Any



@Any 注释定义了一个
多态关联到类
来自多个表格。这种类型的
映射总是需要多于一个
列。第一列保存关联实体的
类型。剩余的
列包含标识符。
不可能为这种
关联指定一个外部
键约束,所以这当然不是$ b $映射的常用方式b(多态)关联。您应该
仅在非常特殊的情况下使用
(例如审计日志,用户会话数据,
等)。

2.4.5.2. @Any

The @Any annotation defines a polymorphic association to classes from multiple tables. This type of mapping always requires more than one column. The first column holds the type of the associated entity. The remaining columns hold the identifier. It is impossible to specify a foreign key constraint for this kind of association, so this is most certainly not meant as the usual way of mapping (polymorphic) associations. You should use this only in very special cases (eg. audit logs, user session data, etc).

尽管我明白这个注解是为了将一个关联属性映射到没有共同祖先实体的不同类型的实体而引入的,但我认为最好引入一个基类键入其他实体将从双向关系继承。

While I understand that this annotation has been introduced to map an association property to different types of entities that don't have a common ancestor entity, I think it would be better to introduce a base type the other entities would inherit from for bidirectional relations.

  • @Any bidirectional relationship fails

这篇关于我如何通过@Any注释的属性进行双向映射?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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