views:

16

answers:

1

In this article http://www.jroller.com/eyallupu/entry/hibernate_the_any_annotation and also in this question http://stackoverflow.com/questions/217831/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?

A: 

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

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.

See also

Pascal Thivent