简体   繁体   中英

Change subclass implementation in hibernate JOINED inheritance

I have two classes that extends my superclass:

superclass:

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "TRADE_ID", discriminatorType = DiscriminatorType.INTEGER)
public abstract class AbstractTrade extends RhEntity {
.
.
.

first child:

@Entity
@Table(name = "INCOMPLETE_TRADE")
@DiscriminatorValue("1")
public class IncompleteTrade extends AbstractTrade {
String customerName;

second child:

@Entity
@Table(name = "COMPLETE_TRADE")
@DiscriminatorValue("2")
public class CompleteTrade extends AbstractTrade {
Customer customer;

Is there any solution when changing an incomplete trade to complete one, only update the additional data (delete record in incomplete table and add in complete table, with updating discriminator column ) without changing the primary key

If using JOINED then the discriminator is arguably of little use (the table that it has a row in defines the "type", the discriminator is only a way of shortcutting this lookup).

Secondly you cannot change the "identity" of an object (and the class of the object is part of that identity).

The ONLY way is to create a new object with this new class (and new identity) and delete the old one

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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