Hibernate mapping a composite key with null values

后端 未结 6 2060
栀梦
栀梦 2020-12-09 09:27

With Hibernate, can you create a composite ID where one of the columns you are mapping to the ID can have null values?

This is to deal with a legacy table that has a

6条回答
  •  爱一瞬间的悲伤
    2020-12-09 10:11

    Unfortunatly, no. I either had to use a workaround:

    I used composit Id for a view(! not table) where rows can be identified by 2 cols exactly (A, B). Although one of the cols (B) can have null values as well as positive integers. So my workaround is that i created a new col in the view: "BKey" and my view is written as if B is null then value of BKey is -1 else BKey = B. (Only positive integers occour in B and null). I also changed my composit id implementation to use BKey instead of B. Hope it helps for somebody..

提交回复
热议问题