Need help implement this scenario in Hibernate inheritance
Cow and Dog are inheriting Animal class,
Both Cow and Dog have "offspring" list
Cow have additional list - monthly vaccine dates
Will this Hibernate representation will be correct?
Is it correct to put the OneToMany Vaccine list on the Cow class
or Its need to be on the Animal class??
Thank you!
@Entity
@Table(name = "animals")
@DiscriminatorColumn(name="animal_type")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
public abstract class Animal{
@Id
@Column(name = "animalId" ,nullable = false)
private String animalId;
@OneToMany(cascade=CascadeType.ALL)
private List<Animal> offsprings = new ArrayList<Animal>();
public List<Animal> getOffsprings() {
return offsprings;
}
...
}
@Entity
@DiscriminatorValue("COW")
public class Coe extends Animal {
@OneToMany(cascade=CascadeType.ALL)
**private List<Vaccine> vaccine = new ArrayList<Vaccine>();**
}
@Entity
@DiscriminatorValue("DOG")
public class Dog extends Animal {
private chipId;
}