Refactoring a Hibernate Object in Subclasses

I have a class that is currently displayed as an object in a database table using Hibernate. This class should be reorganized into an abstract class containing a field common to all its subclasses.

I use annotations to map entity / relationship merge classes.

I would like suggestions / options on how to do this refactoring.

In addition, some recommendations for moving data that is stored in a database (for the future abstract superclass) to one of the specific subclasses.

+6
java database hibernate refactoring
source share
1 answer

First I will create a superclass and add the necessary annotations. You must decide between:

  • Table for class strategy
  • Strategy hierarchy of individual tables in a class.
  • Subclass strategy

I think the Subclass Subclass will work here. You add annotation:

@Entity @Inheritance(strategy=InheritanceType.JOINED) 

To the superclass.

Secondly, I will create tables (tables) that represent subclasses. Remember that they will only have columns that are unique to the subclass, and columns that are shared will remain in the superclass. Then select the rows from the superclass table that belong to each subclass and move the data.

I'm not sure if you are looking for something more specific? This article explains inheritance using Hibernate.

+9
source share

All Articles