I have problems with defining a schema with multiple level inheritance, so in my case I have a schema like bellow :
Model(id,created)
UserModel extends Model (login,password)
CustomerModel extends UserModel (orders)
StoreOwnerModel extends UserModel (stores)
ProductModel extends Model(name,price)
I have set inheritance strategy in Model on TABLE_PER_CLASS, so that means that I want for each sub class of Model create a table.
and the inheritance strategy in UserModel is set to SINGLE_TABLE to have just one table for all UserModel's subClasses.
But in my data base I see that for each UserModel subclasses a table is generated.
and I can't find the DiscriminatorColumn user_type in the generated table table USERS corresponding to UserModel.
here are my entities:
Model.class
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
@MappedSuperclass
public abstract class Model {
@Id
@GeneratedValue(strategy=GenerationType.TABLE)
private Integer id;
@DateTimeFormat(pattern="dd/MM/yyyy hh:mm:ss")
private Date created;
//getters/setters
}
UserModel.class
@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="user_type",discriminatorType=DiscriminatorType.STRING)
@SecondaryTable(name="USERS")
@DiscriminatorValue("user")
public class UserModel extends Model{
@Column(unique=true)
private String login;
//getters & setters
}
CustomerModel.class
@Entity
@DiscriminatorValue(value="customer")
public class CustomerModel extends UserModel{
private List<OrderModel> orders;
//getters & setters
}
StoreOwnerModel.class
@Entity
@DiscriminatorValue(value="store_owner")
public class StoreOwnerModel extends UserModel{
private List<StoreModel> stores;
//getters & setters
}
ProductModel.class
@Entity
public class StoreOwnerModel extends UserModel{
private String name;
private double price;
//getters & setters
}
PS: this is not a duplucated Question, I dont Find this Answer on any of previous ones.
-
4Model isn't an entity, it is a mappedSuperclass and shouldn't even have an inheritance strategy - each entity that extends it will be its own independent entity, only sharing the mapped attributes, not the table. Try removing the inheritance tag as it must be causing an issue with your provider somehow. You can verify this by setting it to single table inheritance - the model should still will not have a table created for it.Chris– Chris2016年06月03日 16:13:31 +00:00Commented Jun 3, 2016 at 16:13
1 Answer 1
according to @chris I should remove @Inheritance from Model entity
and I also removed @SecondaryTable(name="USERS") from UserModel and it worked just perfectly.
Comments
Explore related questions
See similar questions with these tags.