Changing the type of an entity preserving its ID

前端 未结 5 1653
刺人心
刺人心 2020-12-31 11:07

I am using hibernate as a persistence layer. There are 2 entities that live in the same table extending one superclass with single table inheritance strategy.



        
5条回答
  •  一生所求
    2020-12-31 11:22

    You can use your own id (not generated) and do the following:

    1. Retrive B
    2. open transaction
    3. delete B
    4. commit the transaction
    5. open a new transaction
    6. create C and persist it
    7. Close the second transaction

    In this way you will clear the id from the table before re-inserting it as C.

提交回复
热议问题