Reputation: 77
i want to create two table using a abstract super class
i have 3 user's -> Full Time User, part-time user, they have almost the same data
I create the models but the table User is not created :( how do i do? thanks in advance
Model Full time User
@Entity
public class User extends Model{
public String name;
public Date start;
public Date end;
public boolean status;
......
public Project() {
super();
}
}
Model Part-time User
@Entity
public class partTimeUser extends User {
public Time startTime ;
public Time endTime;
}
----------------------------------- 2º REPLY----------------------------------------
Can i do like this? or is diferent when getting the objects?
Model User
@MappedSuperclass
public class User extends Model{
public String name;
public Date start;
public Date end;
public boolean status;
......
public Project() {
super();
}
}
Model Part-time User
@Entity
public class partTimeUser extends User {
public Time startTime ;
public Time endTime; }
}
Class Full User
@Entity
public class partTimeUser extends User {
}
Upvotes: 1
Views: 191
Reputation: 6685
In JPA you should add some annotations about the type of inheritence.
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "USER")
@Entity
public class User ...
@Table(name = "PART_TIME_USER")
@Entity
public class PartTimeUser extends User ...
P.S. The @Table annotation is not necessary. Nevertheless I prefer to define it. It makes the code and its connection to database objects more readable.
Upvotes: 2