I have a class that is currently mapped as an entity in a database table using Hibernate. This class should be refactored into an abstract class containing some field common to all of its subclasses.
I'm using annotations for mapping hibernate entities/relationships classes.
I would like suggestions/variants on how to do this refactoring.
Also, some suggestions on how to move the data that is stored in the database (for the future abstract superclass) into one of the concrete subclasses.
First, I will create the superclass and add the necessary annotations. You have to decide between:
I think the Joined Subclass will work here. You add the annotation:
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
To the super class.
Second, I will create the table(s) that represent the sub classes. Remember these will only have the columns that are unique to the subclass, columns that are shared will remain in the super class. Then select the rows from the super class' table that belong in each subclass and move the data.
I'm not sure if you are looking for something more specific? This article explains inheritance with Hibernate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With