简体   繁体   English

Hibernate在同一个表内级联

[英]Hibernate Cascading within same table

I have a table with the below structure - 我有一张下面结构的桌子 -

SampleTable (
             id pk,
             first_name,
             last_name,
             common_message1,
             common_message2
             )

The records will be inserted in batch in this table and will have different id, first_name, last_name but same common_message1 and common_message2. 记录将在此表中以批处理方式插入,并具有不同的id,first_name,last_name,但相同的common_message1和common_message2。

The records will be like: 记录将如下:

| 1 | Test1  |  last1  | this is same message1   | this is same message2 |        
| 2 | Test2  |  last2  | this is same message1   | this is same message2 |   
| 3 | Test3  |  last3  | this is same message1   | this is same message2 |  
| 4 | Test4  |  last4  | this is same message3   | this is same message4 |   
| 5 | Test5  |  last5  | this is same message3   | this is same message4 |     

NOTE - I can not normalize the table due to some design limitation in my project 注 - 由于我的项目中的某些设计限制,我无法规范化表格

How should I handle this duplicate entries in the table, should I store them multiple times as shown above, if yes then how to insert or update so as to make sure all are same and updated properly, Or is there any other efficient way to handle such scenario. 我应该如何处理表中的这些重复条目,如果我将它们存储多次,如上所示,如果是,那么如何插入或更新以确保所有相同并正确更新,或者是否有任何其他有效的方法来处理这种情况。

Thanks in advance 提前致谢

By updated, I assume you mean you want to make updates to the "common-message"s. 通过更新,我认为你的意思是你想要更新“共同消息”。

Ie When you change the comments in one row you want it to change in all the rows with matching comments. 即,当您更改一行中的注释时,您希望它在具有匹配注释的所有行中更改。

Your only real option is to retrieve all the rows with a WHERE clause on common_message1 and common_message2 then update those fields for the whole collection. 您唯一真正的选择是在common_message1common_message2上使用WHERE子句检索所有行,然后为整个集合更新这些字段。

When not dealing with the messages you'd obviously want to treat them as individual entities. 当不处理消息时,您显然希望将它们视为单独的实体。

Ie When you change the first_name or last_name 即更改first_namelast_name

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM