我有一个组合主键,其中一个键为空。实体中必须有哪些注释,这样我才能使用这种JPA获取数据:
ID_FIRST_KEY |ID_SECOND_KEY |DATA
-------------------------------------
1 |100 |data1
1 |200 |data2
1 |null |data3
2 |100 |data4
......................................我尝试使用IdClass注解和EmbeddedId注解,但得到了异常:
Exception Description: The primary key read from the row [ArrayRecord(
DATA.ID_FIRST_KEY => 1
DATA.ID_SECOND_KEY => null
DATA.DATA => data3)] during the execution of the query was detected to be null. Primary keys must not contain null.例如,使用了数据,但在实际项目中使用了类似的数据,因此无法用值替换null。
发布于 2021-09-16 08:59:09
您不能使任何主键为空,如果您的值为null,则它不应该是主key.Instead的一部分。您可以为主键添加一个新列
有关更多细节,请访问:NULL value in multi-column primary key
https://stackoverflow.com/questions/69205196
复制相似问题