开发者

Hibernate: mapping two classes to a common third class

I am searching for the correct mapping of a many-to-one relationship of two classes pointing on a third one. An example is shown in the image below:

Hibernate: mapping two classes to a common third class

In words; a Person has 1..n addresses a Company has 1..n addresses

I'd like to have a single table for all addresses. For the moment a uni-directional relation is开发者_如何转开发 all I need, but it would be also nice to see how this works with bi-directional relations.

I believe the correct database representation is like in the next image

Hibernate: mapping two classes to a common third class

But I don't know how to translate this into a hibernat xml file or a java class using hibernate annotations.

This problem has been discussed 5 years ago in the hibernate forum: "https://forum.hibernate.org/viewtopic.php?t=961387" but I think they found no satisfactory solution.

regards.

Julien


That's a very normal "unidirectional one-to-many with join table" relationship as described in Chapter 8 of the Hibernate reference and Chapter 2 of the Annotations reference.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜