首页 \ 问答 \ 在关系数据库中链接未知表的外键(linking foreign Key of unknown table in a relational database)

在关系数据库中链接未知表的外键(linking foreign Key of unknown table in a relational database)

我目前正试图建立一个关系数据库(H2),它将JAVA模型的面向对象结构投影到我的数据库的关系表中。 我正在使用JDBC和H2 RDBMS。

所以这是我的问题:我有一个“属性”类型的对象,应该存储在表“属性”中。 该属性的所有者可以是“Function”类型的对象或“Block”类型的对象,它们都有自己的表格。 一个属性对象只能由一个对象(函数或块)拥有,从而使其成为1:n基数。

然而,我正在努力如何将属主包含在属性表中。 如果我创建一个名为“ownerID”的表并将所有者的ID(全局唯一ID btw)存储在该表中,那么数据库缺少关于哪个表包含此ID(即使其为GUID)的信息。

- 例如,是否可以包含另一个包含owner_ID所属表的名称的列?

另一个想法是包含一个“functionOwnerID”列和一个“blockOwnerID”,并留下其中一个为空,但这对我来说似乎是一个相当脏的解决方案。

我希望我对这个问题的描述很清楚,并且提前感谢!

最好的问候,莫里茨


I am currently trying to set up a relational database (H2) that projects an object orientated structure of JAVA Model into the relational tables of my database. I am using the JDBC and H2 RDBMS.

So Here is my problem: I have an object of type "attribute" that is supposed to be stored in the table "attribute". The owner of this attribute can either be an object of type "Function" or of type "Block" who both have a table on their own. One attribute-object can only be owned by one object (either function or block), making this a 1:n cardinality.

I am however struggling with how to include the owner in the attribute table. If I create a table named "ownerID" and store the ID of the owner (a globally unique ID btw) in it, the Database is missing the information about which table is containing this ID (even though its a GUID).

-Is it okay for example, to include another column containing the name of the table that the owner_ID belongs to ?

-another idea was to include one "functionOwnerID" column and one "blockOwnerID" and leaving one of them empty, but this seems like a rather dirty solution to me.

I hope my description of the problem was clear, and thanks in advance !

best regards, Moritz


原文:https://stackoverflow.com/questions/42718667
更新时间:2024-01-24 07:01

相关问答

更多
  • 一个小小的题外话...... 您尝试做的事情可以很容易地使用CSS和:hover伪 .imgWrapper, .imgWrapper img{ position:relative; display:inline-block; vertical-align:top; } .imgWrapper span{ position:absolute; z-index:1; top:0; bottom:0; left:0; right:0; background:rgba ...
  • 你应该看看这个插件: https://github.com/kemayo/maphilight 和演示: http://davidlynch.org/js/maphilight/docs/demo_usa.html 如果有什么,你可能可以借用一些代码来修复你的错误。 You should check out this plugin: https://github.com/kemayo/maphilight and the demo: http://davidlynch.org/js/maphilight/d ...
  • 这是行不通的,因为this在你的情况下是a标签,而不是图像。 因此,您要更改此标记的高度而不是图像。 相反,你可以使用find()函数来选择标签内的图像,如下所示: $(document).ready(function() { $('a.delete').on('mouseenter', function() { $(this).find('img').css({ 'height': '175px' }); }); });