I have two entities, one is Item, another Fruit. I want to implement first as super class of the other, and I want all the parameters from the super class to be inherited by its subclass.
Also I want, when building database to bind that superclass table and all its properties to the subclass table, i.e., if I create more subclasses, I don't want for all of them to write values which were supposed to be in super class.
How should I achieve this?
item.java
@MappedSuperclass
@DiscriminatorColumn(name="Item")
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class Item implements java.io.Serializable
{
// here goes all values of the class Item
}
fruit.java
@Entity
@PrimaryKeyJoinColumn(name="ART_ID")
public class Fruit extends Item implements java.io.Serializable{
// here goes proper values of this class
}
database.db
create table Item
(
ITEM_ID bigint not null auto_increment,
ITEM_NAME varchar(25) not null,
);
create table Fruit
(
FRUIT_DATEFROZEN date,
);
);